Repository navigation
reduce_canonicalize: reserve the memo and hash-cons maps - #60
Merged
olydis merged 1 commit intoOct 3, 2026
Merged
Conversation
Growing an unordered_map rehashes every entry it holds. Reducing forest's library fills the memo to 6.8M entries and hash_cons and node_defs_idx to 2.1M each, and that growth, with the fuller tables it leaves, was over half the run. Reserved up front, with the build's flags (medians of 3, back to back; output and --stats-per-symbol table byte-identical): forest library 16.0 -> 7.05 s (peak RSS 1078 -> 1145 MB) arboretum bundle 10.3 -> 4.58 s (742 -> 843 MB) A tiny module pays for it: 0.003 -> 0.14 s, 10 -> 207 MB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018ffv5AybPTpV56D5vuayQr
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.
Three
reservecalls inreduce_canonicalize.cpp:apply_memo(1<<24),hash_consandnode_defs_idx(1<<22 each). Reducing forest's library fills the memo to 6.8M entries and the other two maps to 2.1M each. Without the reserves, rehashing as they grow, plus the fuller tables left behind, takes more than half the run.Effect
Inputs and flags are the ones forest's build uses (
build.shphases 5 and 5b,--fuel=100000000, plus--stats-per-symbolfor the library). Each figure is the median of 3 runs, with the old and new binaries run back to back on the same machine..dag-bundle-librarytest.sh's*.dag)Forest runs the two reductions one after the other, saving about 14.7 s. Its
build/teststeps run three tiny reductions, which add about 0.45 s, so a full build saves about 14.3 s net.Other variants measured (lib / arb, seconds; baseline 16.2 / 10.6):
apply_memoreserve alone: 9.8 / 7.0apply_memo+hash_cons: 8.6 / 5.8hash_consandnode_defs_idxat 1<<23: 7.1 / 4.3, but +70 MBmax_load_factor(0.5)with no reserve: 12.1 / 8.9std::vectorper task: −0.5 to −2 s alone, and nothing on top of the reservesValidation
cmp) on both bundles, and so is the--stats-per-symboltable (TOTAL 4,712,299). Forest's committedbuild/testreduce expect files (id,Bool.not,pipeline/03-reduced.dag) are also unchanged. None of the three maps is ever iterated, so the bucket count cannot affect output order.implementation/cpp/dag-machine/test.shpasses underLC_ALL=Cand underLC_ALL=C.UTF-8: jets 5, runner 21/21, reduce_canonicalize 4/4.Caveats
Merge order
None required. Forest picks this up when it bumps the tree-calculus pin through arboretum.
🤖 Generated with Claude Code
https://claude.ai/code/session_018ffv5AybPTpV56D5vuayQr