You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
engine: compute run-invariant variables once per run, not every step #712
Constants and auxiliaries that depend only on constants get the same value every step, yet the VM recomputes them every step.
The idea was to evaluate them once per run_to (and again after set_value) and copy their values into each saved row.
Status
Half of this is on main and half was measured and not merged:
On main: a classifier marks the root model's run-invariant flow variables and orders them first in the flow program, recording where they end. Nothing at run time reads that boundary; only tests do. It costs about 0.6% of compile time. On C-LEARN it marks 868 slots, 45% of the root flow opcodes.
Not merged: running that invariant prefix once per run_to. It is complete and passes every gate (results byte-identical, wasm parity, no allocation), and is preserved on the experiment-712-b2-execution branch. It removed only 1.3% of executed instructions on C-LEARN, because most per-step work is in module evaluation and per-element array loops, not the root model's scalar flows. Wall-clock change was within build-to-build noise.
Fix
The open question is what to do with the half on main.
Recommended: delete the classifier and the recorded boundary, since nothing uses them.
The branch keeps the full implementation if a future CPU or profile makes it worthwhile.
Alternative: merge the execution half for its 1.3% instruction cut and roughly 8% fewer branch misses, which may matter more on a CPU limited by mispredicts.
That adds a snapshot-and-copy step to every saved row.
Pointers
src/simlin-engine/src/db/invariance.rs and src/simlin-engine/src/compiler/invariance.rs: the classifier
flows_invariant_opcode_len in src/simlin-engine/src/bytecode.rs and compiler/symbolic.rs; its only readers are test helpers in vm.rs
docs/design-plans/2026-06-04-time-invariant-hoisting.md: design of both halves
Status after the engine-vm-perf round (full data in docs/design/engine-performance.md, negative result #3):
B1 (KEPT, on engine-vm-perf): conservative run-invariance classifier + root flow-runlist partition + flows_invariant_opcode_len metadata. Behavior-neutral (VDF byte-exact, wasm parity), perf-neutral, +0.56% compile. Adversarially reviewed twice (initial REQUEST-CHANGES on a doc claim + a compile regression, both fixed; final APPROVE). The bit-constancy oracle pins soundness: C-LEARN 868 invariant slots / 0 violations, WORLD3 78 / 0.
B2 (execution stage: NOT merged; complete implementation preserved on branch experiment-712-b2-execution, commit bcfcd6b3). Splits root flows at the recorded boundary, evaluates the invariant prefix once per run_to, scatters the snapshot per step, literal overrides hit both halves. All gates green including byte-exactness, wasm parity, and zero-alloc. It did not clear the keep bar:
Removing ~45% of the root flow stream's STATIC opcodes from per-step execution removed only -1.3% of executed instructions -- C-LEARN's per-step work is dominated by module evaluations and per-element array loops, which the root-stream prefix does not touch. The static-opcode share from the measurement phase was a bad proxy for executed work.
The wall-clock delta is inside the build-layout noise floor: two independent build pairs measured opposite signs (+3.5% vs -1.0% on C-LEARN; two builds of the identical base source differed by ~6 ms). World3 trended slightly negative both times (+1..10%).
Retry condition: branch-misses fell -8.4%, so a mispredict-bound microarchitecture (the Ryzen 9950X from round 1, where the dispatch indirect branch dominates) may see a genuine win. Anyone retrying: cherry-pick bcfcd6b3, and per the methodology note, use layout-stable counters (perf stat instructions/branch-misses/cycles) or multiple independent builds per side -- a single build pair cannot resolve effects under ~4%.
(Process note: the experiment-branch snapshot was initially committed with --no-verify, then amended with the full pre-commit hook run; the commit body's last paragraph predates that amend.)
changed the title [-]engine: time-invariant variable hoisting — a constant phase evaluated once per run_to[/-][+]engine: compute run-invariant variables once per run, not every step[/+]on Oct 12, 2026
Activity
bpowers commentedon Jun 4, 2026
Status after the engine-vm-perf round (full data in docs/design/engine-performance.md, negative result #3):
B1 (KEPT, on engine-vm-perf): conservative run-invariance classifier + root flow-runlist partition +
flows_invariant_opcode_lenmetadata. Behavior-neutral (VDF byte-exact, wasm parity), perf-neutral, +0.56% compile. Adversarially reviewed twice (initial REQUEST-CHANGES on a doc claim + a compile regression, both fixed; final APPROVE). The bit-constancy oracle pins soundness: C-LEARN 868 invariant slots / 0 violations, WORLD3 78 / 0.B2 (execution stage: NOT merged; complete implementation preserved on branch
experiment-712-b2-execution, commit bcfcd6b3). Splits root flows at the recorded boundary, evaluates the invariant prefix once per run_to, scatters the snapshot per step, literal overrides hit both halves. All gates green including byte-exactness, wasm parity, and zero-alloc. It did not clear the keep bar:(Process note: the experiment-branch snapshot was initially committed with --no-verify, then amended with the full pre-commit hook run; the commit body's last paragraph predates that amend.)
[-]engine: time-invariant variable hoisting — a constant phase evaluated once per run_to[/-][+]engine: compute run-invariant variables once per run, not every step[/+]