Skip to content

Skip the assigned-variable walk when a Lambda arena holds no assignment - #94

Merged
jfrolich merged 2 commits into
ocaml-to-rust-rewritefrom
skip-assigned-variable-walk
Nov 11, 2026
Merged

jfrolich merged 2 commits into
ocaml-to-rust-rewritefrom
skip-assigned-variable-walk

Conversation

@jfrolich

Copy link
Copy Markdown
Owner

What

arena_assigned_variables returns the empty set without walking the term when the Lambda arena holds no assignment node.

Why

ec8f971 (the port of "Evaluate the arguments of an inlined call left to right") needs to know which variables a term assigns, so that reads of them keep their order. It asks in four places: once per run of the alias simplification pass, once per run of the let simplification pass, once before compiling to JS, and once for every inlined call. Each answer walked the whole term recursively and built a hash set.

The set is almost always empty: only a mutable variable that is kept local produces an assignment, and the comment at the call site in lam_pass_remove_alias.rs already says so. In a profile of a 3,735-module application the walk was 0.43% of CPU, and the commit as a whole raised a clean build by about 0.5 G instructions.

How

LamArena records in push whether an Assign node was ever added (may_assign). With none, no term of the arena can assign anything, so the answer is the empty set. With one anywhere in the arena, the walk runs exactly as before. The result is therefore the same in every case.

Measurements

Clean build of a 3,735-module application, release build with one codegen unit, the same binary with and without the walk, alternating pairs, retired instructions from /usr/bin/time -l:

Workers Walk Skip Paired difference
1 (n=8) 83.82 G 83.33 G −0.49 ± 0.14 G (−0.6%)

The 3,980 generated files are byte-identical.

Tests

an_arena_without_assignments_needs_no_walk_for_assigned_variables in lambda::arena: an arena without assignments answers empty; adding one brings the walk back for terms that contain it and terms that do not; a cloned arena keeps the answer.


Started by Jaap Frolich in this Assistant session

open-session-submodule Bot and others added 2 commits November 11, 2026 18:22
ec8f971 (evaluate the arguments of an inlined call left to right)
asks which variables a term assigns in four places: once per run of the
alias and let simplification passes, once before compiling to JS, and
once for every inlined call. Each answer walked the whole term and
built a hash set, and the set is almost always empty: only a mutable
variable that is kept local produces an assignment.

The arena now records whether an assignment node was ever added to it,
and `arena_assigned_variables` returns the empty set without walking
when none was. With an assignment anywhere in the arena the walk runs
as before, so the result is the same in every case.

Clean build of a 3,735-module application, one-codegen-unit release
build, the same binary with and without the walk, alternating pairs,
1 worker: 83.82 -> 83.33 G instructions (paired -0.49 +- 0.14, n=8).
The 3,980 generated files are identical.

Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://jakes-mac-mini.tail23a77e.ts.net:8443/session/os-01a1c9fa-0c5d-7912-a93b-3e7f38e53547
Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://jakes-mac-mini.tail23a77e.ts.net:8443/session/os-01a1c9fa-0c5d-7912-a93b-3e7f38e53547
Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
@jfrolich
jfrolich force-pushed the skip-assigned-variable-walk branch from da0a390 to f0e9d04 Compare November 11, 2026 17:23
@jfrolich
jfrolich merged commit fee64ab into ocaml-to-rust-rewrite Nov 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant