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: compile apply-to-all equations to loops, not one op per element #1025
Every apply-to-all or per-element array equation compiles to one assignment per element, so bytecode size and VM work grow with the number of array elements rather than the number of equations.
The proposal is to compile an apply-to-all equation to a VM loop over its elements instead.
Example
C-LEARN has 934 variables and 5,215 array elements (30,123 with LTM).
The motivating case is four C-LEARN equations of this shape:
sorted target active[COP,Target] = VECTOR ELM MAP(Target is Active[COP,t1], Target Order[COP,Target])
(likewise sorted target type, value, year).
Per-element compilation sets up one VECTOR ELM MAP per COP element instead of sharing work.
On a compiler-cleanup branch that was later replaced by PR #1040, this measured +6.9% run time on plain C-LEARN and +1.0% with LTM.
Whether the same cost exists on main has not been measured.
Why it matters
Only run time; results are correct.
C-LEARN is the only model where this has been measured.
Fix
First, measure plain and LTM C-LEARN run time on main and profile how much goes to unrolled array equations.
Only if that is significant, compile the sorted target * shape as a loop: a destination-writing form of the VM's existing iteration opcodes (BeginIter, LoadIterViewAt, StoreIterElement, NextIterOrJump, EndIter), with wasm parity.
Any equation the loop form cannot handle exactly (EXCEPT, element maps, subranges, members of a simultaneous-equation cycle, ...) stays per-element; the decision must use the resolved subscripts, not a second resolution path.
Pointers
src/simlin-engine/src/compiler/array_operand.rs: where array values are materialized today
Updated the issue body after the Phase 6b implementation and adversarial review. It now reflects the post-subscript-resolution materializer, makes batched array-producing builtins part of acceptance, and records the exact plain/LTM artifact and runtime residuals carried forward from PR #1032.
changed the title [-]engine: lower plain apply-to-all equations to VM loops instead of compile-time per-element unrolling[/-][+]engine: compile apply-to-all equations to loops, not one op per element[/+]on Oct 12, 2026
Its +6.9% run-time figure was measured on PR #1032, which was closed and replaced by #1040 (whose body reports run time going down), so the cost on main is unknown. Adding a second lowering tier conflicts with keeping the compiler simple; reopen if a profile on main shows unrolled array equations dominating run time.
Activity
engine: materialize arrays after subscript resolution
bpowers commentedon Aug 27, 2026
Updated the issue body after the Phase 6b implementation and adversarial review. It now reflects the post-subscript-resolution materializer, makes batched array-producing builtins part of acceptance, and records the exact plain/LTM artifact and runtime residuals carried forward from PR #1032.
[-]engine: lower plain apply-to-all equations to VM loops instead of compile-time per-element unrolling[/-][+]engine: compile apply-to-all equations to loops, not one op per element[/+]bpowers commentedon Oct 12, 2026
Closing as won't fix.
Its +6.9% run-time figure was measured on PR #1032, which was closed and replaced by #1040 (whose body reports run time going down), so the cost on main is unknown. Adding a second lowering tier conflicts with keeping the compiler simple; reopen if a profile on main shows unrolled array equations dominating run time.