Repository navigation
Allocate an environment table layer's map on its first binding - #93
Merged
Merged
Conversation
jfrolich
force-pushed
the
env-lazy-layer-maps
branch
from
November 11, 2026 17:23
1bbe060 to
b2af266
Compare
jfrolich
force-pushed
the
env-recent-bindings
branch
from
November 11, 2026 17:23
7b952b2 to
93be21e
Compare
jfrolich
changed the base branch from
env-recent-bindings
to
ocaml-to-rust-rewrite
November 11, 2026 17:53
Every `open` starts a new layer in each of the environment's seven binding tables, and each layer held one or two persistent hash maps. An empty persistent map still owns a root node of about 1.5 KB and a reference-counted hasher, and opening a layer built the maps twice (once for the value left behind by `mem::take`). Most layers never get a binding of their own, and with the recent-binding list a layer needs its map only once sixteen bindings have been added to it. `LayerMap` wraps the map in an `Option` that is filled by the first insertion; readers see an empty map until then. Clean build of a 3,735-module application, one-codegen-unit release build, the same binary with lazy and eager maps, alternating pairs, 1 worker: 82.67 -> 82.45 G instructions (paired -0.21 +- 0.16, n=12). Peak RSS unchanged; 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
force-pushed
the
env-lazy-layer-maps
branch
from
November 11, 2026 17:54
b2af266 to
6c2d57f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #91 (the recent-binding list), which this change relies on.
What
The persistent map of an environment table layer is allocated by its first insertion instead of when the layer is created.
Why
Every
openstarts a new layer in each of the environment's seven binding tables (values, types, constructors, labels, modules, module components, module types). Each layer held one or two persistent hash maps, and an empty persistent map still owns a root node of about 1.5 KB and a reference-counted hasher. Opening a layer also built the maps twice, once for the valuemem::takeleaves behind. That is about 18 root nodes allocated, zeroed and later dropped peropen, and every compilation opens the standard library before anything else. Most layers never get a binding of their own, and with #91 a layer needs its map only once sixteen bindings have been added to it.LayerMapwraps the map in anOption; readers see an empty map until the first insertion fills it.Behaviour
No change: the 3,980 generated files of a 3,735-module application are byte-identical.
Measurements
Clean build of that application, release build with one codegen unit, the same binary with lazy and eager maps, alternating pairs, retired instructions from
/usr/bin/time -l:Peak RSS is unchanged.
Tests
a_table_layer_has_no_map_until_a_binding_is_moved_into_itintypes::env, for both table kinds, including lookups through a layer without a map. The 228 tests undertypes::pass.Started by Jaap Frolich in this Assistant session