Repository navigation
Add environment bindings to a short list in front of the map - #91
Merged
Merged
Conversation
jfrolich
force-pushed
the
env-recent-bindings
branch
from
November 11, 2026 12:39
f3a1e14 to
7b952b2
Compare
Every typed-tree node records the environment it was checked in, so each version of an environment's binding tables stays alive until the module is torn down. The local bindings of a table are a persistent hash map, and adding one binding to a map a snapshot shares copies the map nodes on the path to it, each up to 32 entries wide: about 1 KB or more allocated and kept per binding, a reference count taken for every entry copied, and the same again to release them at teardown. A table now keeps the bindings added since its map was last extended in a linked list, newest first, and moves the list into the map once it holds 16 of them. Adding a binding allocates one small node, and the map is copied once per batch. Readers look in the list first; each node carries a bit set of the names in the list below it, so a lookup of a name that is not listed does not walk it. Clean build of a 3,735-module application, one-codegen-unit release builds, alternating pairs: - 1 worker: 79.99 -> 79.40 G instructions (paired -0.59 +- 0.22, n=6), peak RSS 954 -> 942 MB. - 10 workers, same binary with the list on and off: 82.33 -> 81.75 G (paired -0.58 +- 0.16, n=10), peak RSS 1267 -> 1239 MB. Generated files (3,980) and the incremental build record 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-recent-bindings
branch
from
November 11, 2026 17:23
7b952b2 to
93be21e
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.
What
A table of environment bindings (
IdTbl: values, types, modules, module types) now keeps the bindings added since its map was last extended in a short linked list, newest first, and moves the list into the persistent map once it holds 16 of them.Why
Every typed-tree node records the environment it was checked in, so each version of an environment's tables stays alive until the module is torn down. The local bindings were held only in a persistent hash map, and adding one binding to a map that a snapshot shares copies the map nodes on the path to it. Each node is up to 32 entries wide, so one
letallocated and kept 1 KB or more, took a reference count for every entry copied, and paid the same again to release it at teardown. In a profile of a 3,735-module application, adding values was 1.06% of CPU and dropping the recorded environments 1.14%.With the list, adding a binding allocates one small node and the map is copied once per batch. Readers look in the list first. Each node carries a bit set of the names in the list below it, so a lookup of a name that is not listed does not walk it.
Behaviour
No change. Every reader of the table was updated to read the list before the map:
find_allsee list bindings as the newest ones;Measurements
Clean build of a 3,735-module application, release builds with one codegen unit, alternating pairs, retired instructions from
/usr/bin/time -l. Re-measured after rebasing onto 4c8358d:Before the rebase (base c7fabe6) the same comparison gave −0.59 ± 0.22 G at 1 worker and, with the list switched on and off inside one binary, −0.58 ± 0.16 G at 10 workers. Batch sizes 8, 12, 16, 24, 32 and 64 were compared in one binary; 16 was best single-threaded and within noise of 12 at 10 workers.
The 3,980 generated files are byte-identical to trunk's, before and after the rebase.
Tests
Three unit tests in
types::env:recent_bindings_read_like_map_bindingscompares every reader of a table that uses the list against one that adds straight to the map, after each of 53 additions with rebinding and an open in the middle of a batch;adding_to_a_table_leaves_a_snapshot_and_its_map_alonechecks that an addition after a snapshot does not copy the map and that the snapshot keeps its view;updating_a_recent_binding_leaves_a_snapshot_alone.Started by Jaap Frolich in this Assistant session