CekState record optimization + profiling: 1.5x speedup, root cause found
Transpiler (transpiler.sx): detects CEK state dict literals (5 fields: control/env/kont/phase/value) and emits CekState OCaml record instead of Dict(Hashtbl). Eliminates 200K Hashtbl allocations per page. Bootstrapper: skip stdlib.sx (functions already registered as OCaml primitives). Only transpile evaluator.sx. Runtime: get_val handles CekState with direct field access. type_of returns "dict" for CekState (backward compat). Profiling results (root cause of slowness): Pure eval: OCaml 1.6x FASTER than Python (expected) Aser: OCaml 28x SLOWER than Python (unexpected!) Root cause: Python has a native optimized aser. OCaml runs the SX adapter-sx.sx through the CEK machine — each aserCall is ~50 CEK steps with closures, scope operations, string building. Fix needed: native OCaml aser (like Python's), not SX adapter through CEK machine. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -724,7 +724,7 @@ let dispatch env cmd =
|
||||
(try
|
||||
ignore (env_bind env "expand-components?" (NativeFn ("expand-components?", fun _args -> Bool true)));
|
||||
(* Enable batch IO mode *)
|
||||
io_batch_mode := true;
|
||||
io_batch_mode := true; Sx_ref._cek_steps := 0;
|
||||
io_queue := [];
|
||||
io_counter := 0;
|
||||
let exprs = Sx_parser.parse_all src in
|
||||
@@ -749,8 +749,8 @@ let dispatch env cmd =
|
||||
(* Flush batched IO: send requests, receive responses, replace placeholders *)
|
||||
let final = flush_batched_io result_str in
|
||||
let t2 = Unix.gettimeofday () in
|
||||
Printf.eprintf "[aser-slot] eval=%.1fs io_flush=%.1fs batched=%d result=%d chars\n%!"
|
||||
(t1 -. t0) (t2 -. t1) n_batched (String.length final);
|
||||
Printf.eprintf "[aser-slot] eval=%.1fs io_flush=%.1fs batched=%d result=%d chars cek_steps=%d\n%!"
|
||||
(t1 -. t0) (t2 -. t1) n_batched (String.length final) !Sx_ref._cek_steps;
|
||||
send (Printf.sprintf "(ok-raw %s)" final)
|
||||
with
|
||||
| Eval_error msg ->
|
||||
|
||||
Reference in New Issue
Block a user