CEK loop: use local int ref instead of Atomic for step counter
Atomic.fetch_and_add on every CEK step added unnecessary overhead. The step counter is per-invocation (not shared across threads), so a plain int ref with incr is sufficient and faster. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -382,15 +382,16 @@ and expand_macro mac raw_args env =
|
|||||||
and cek_run state =
|
and cek_run state =
|
||||||
let s = ref state in
|
let s = ref state in
|
||||||
(try
|
(try
|
||||||
|
let n = ref 0 in
|
||||||
while not (match cek_terminal_p !s with Bool true -> true | _ -> false) do
|
while not (match cek_terminal_p !s with Bool true -> true | _ -> false) do
|
||||||
s := cek_step !s;
|
s := cek_step !s;
|
||||||
let n = Atomic.fetch_and_add _step_count 1 in
|
incr n;
|
||||||
if n land 4095 = 0 then begin
|
if !n land 4095 = 0 then begin
|
||||||
let lim = Atomic.get _step_limit in
|
let lim = Atomic.get _step_limit in
|
||||||
if lim > 0 && n >= lim then
|
if lim > 0 && !n >= lim then
|
||||||
raise (Eval_error (Printf.sprintf "Render step limit exceeded (%d steps)" n));
|
raise (Eval_error (Printf.sprintf "Render step limit exceeded (%d steps)" !n));
|
||||||
if n land 1048575 = 0 && n > 0 then
|
if !n land 1048575 = 0 then
|
||||||
Printf.eprintf "[cek] %d steps, phase=%s control=%s\n%!" n
|
Printf.eprintf "[cek] %d steps, phase=%s control=%s\n%!" !n
|
||||||
(match cek_phase !s with String p -> p | _ -> "?")
|
(match cek_phase !s with String p -> p | _ -> "?")
|
||||||
(String.sub (Sx_runtime.value_to_str (cek_control !s)) 0
|
(String.sub (Sx_runtime.value_to_str (cek_control !s)) 0
|
||||||
(min 80 (String.length (Sx_runtime.value_to_str (cek_control !s)))))
|
(min 80 (String.length (Sx_runtime.value_to_str (cek_control !s)))))
|
||||||
|
|||||||
Reference in New Issue
Block a user