Repository navigation
Share a loaded unit's alias rewrites between compilations - #92
Merged
Merged
Conversation
A compilation records, for every unit it loads, which flattened module names the unit's alias submodules stand for (`module JSON = Stdlib_JSON` makes `Stdlib_JSON` mean `Stdlib.JSON`). It did so by walking the unit's signature and inserting each rewrite into its own hash table, after probing that table and the shared registry twice per alias. Every compilation opens the standard library, whose signature is mostly such aliases, so every module compiled paid for the same walk and the same insertions. A loaded unit now computes its rewrites once, into a table kept on the shared structure, and a compilation that reaches the unit under its own name adds a reference to that table. Lookups consult the compilation's own entries, the registry and then the unit tables in load order, which is the order the entries would have been recorded in, so the first rewrite of a name still wins. A unit reached through an alias, whose rewrites carry that prefix, is recorded entry by entry as before. Clean build of a 3,735-module application, one-codegen-unit release build, the same binary with the table on and off, alternating pairs: - 1 worker: 79.83 -> 79.57 G instructions (paired -0.27 +- 0.16, n=8). - 10 workers: 82.21 -> 81.99 G (paired -0.22 +- 0.15, n=12). Peak RSS unchanged. 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
prelude-setup-once
branch
from
November 11, 2026 17:23
5de2def to
332a365
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 loaded unit's alias rewrites are computed once and shared by reference with every compilation that loads the unit, instead of being collected again per compilation.
Why
A compilation records, for every unit it loads, which flattened module names the unit's alias submodules stand for:
module JSON = Stdlib_JSONmakesStdlib_JSONmeanStdlib.JSON. It did that by walking the unit's signature and inserting each rewrite into its own hash table, probing that table and the shared registry twice per alias. Every compilation opens the standard library, whose signature is mostly such aliases, so every module compiled repeated the same walk and the same insertions. In a profile of a 3,735-module application this was 0.45% of CPU.How
PersStructcaches the table of its own rewrites (own_alias_rewrites), built on first use. The structure is shared between compilations, so the table is too.AliasPrefixRewriteskeeps a list of the tables of loaded units, in load order. A lookup consults the compilation's own entries, the registry and then the unit tables in order, which is the order the entries would have been recorded in, so the first rewrite of a name still wins. New entries are refused when a unit table already holds the name.Behaviour
No change: the 3,980 generated files of the application are byte-identical to trunk's.
Measurements
Clean build of a 3,735-module application, release build with one codegen unit, the same binary with the table on and off, alternating pairs, retired instructions from
/usr/bin/time -l:Peak RSS is unchanged.
Tests
Two unit tests in
cmi::persistent_env:a_units_alias_table_reads_like_recording_each_of_its_rewritescompares every reader of the rewrites between walking two units' signatures and adding their tables, with an earlier entry that must win and later entries that must lose;a_loaded_unit_shares_its_alias_table_unless_it_is_reached_through_an_alias.Started by Jaap Frolich in this Assistant session