perf: use SsoHashSet for small module chunk memberships - #15731
Conversation
📦 Binary Size-limit
❌ Size increased by 20.00KB from 68.77MB to 68.79MB (⬆️0.03%) |
Rsdoctor Bundle Diff Analysis
Found 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
Merging this PR will improve performance by 3.58%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | rust@build_chunk_graph |
26.2 ms | 25.2 ms | +3.58% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing codex/chunk-graph-module-sso-set (8eb5682) with main (d4cd073)2
Footnotes
-
47 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
No successful run was found on
main(f077888) during the generation of this report, so d4cd073 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
|
@codspeedbot explain why performance improved |
Why
|
| Subtree | BASE | HEAD | Δ |
|---|---|---|---|
ChunkGraph::connect_chunk_and_module |
1.87 ms (7.14%) | 0.99 ms (3.93%) | −0.88 ms |
↳ HashMap<ChunkUkey, ()>::insert |
1.00 ms (3.85%) | not in profile (<1%) | −1.00 ms |
↳ ↳ RawTable::reserve_rehash (table alloc + growth) |
781 µs (2.99%) | — | −781 µs |
CodeSplitter::add_and_enter_module (its parent) |
11.7 ms | 10.8 ms | −0.9 ms |
CodeSplitter::split |
16.3 ms | 15.4 ms | −0.9 ms |
That −0.88 ms is ~85% of the total benchmark delta, and it is exactly the cost the PR targets: for the common case of a module belonging to only a few chunks, no hashbrown table is allocated and no rehash/growth happens — the ukeys stay inline. The residual growth cost that remains is on the ChunkGraphChunk side (chunk → modules), which the PR does not change.
Everything else is flat, which is what makes the attribution solid rather than a codegen or allocator artifact:
memcpyself time 993.7 µs in both runs (identical to the tenth of a µs),probe_seq1.1 ms bothprepare_module_connection_map5.6 ms both,process_block7.6 ms both,get_block_modules4.3 ms both,enter_module8.7 ms bothChunkGraph::add_module765 → 752 µs, allocator totals unchanged (mi_malloc_aligned2.8 → 2.7 ms) — no allocation was pushed elsewhere
Stability check: comparing head against your branch's own first implementation commit (33fadc5) shows rust@build_chunk_graph as untouched, so the 25.2 ms value reproduces across the branch and is not run-to-run jitter. This matters because CodSpeed flagged different runner CPUs (EPYC 7763 → 9V74) between base and head; a cross-CPU shift would move memcpy/library subtrees too, and here they are byte-identical.
Scope of the win: it applies where chunk memberships are built. The bundle walltime cases are classified untouched, so this is a chunk-graph phase improvement, not a ~3.6% reduction in overall bundling time.
Summary
- Warming up the performance wizard...
- Analyze why rust@build_chunk_graph improved — Compared base (d4cd073) and head (8eb5682) Simulation flamegraphs; delta localized to connect_chunk_and_module
- Check the result is stable, not runner noise — Cross-checked the branch's own earlier run (33fadc5): build_chunk_graph unchanged across branch commits
- Handling comment — Comment handling finished successfully
Learnings updated. See what CodSpeed remembers about this repository.
Was this response helpful? React with 👍 or 👎 to help us improve CodSpeedBot.
Motivation
ChunkGraphModule::chunksallocates a hash table even when a module belongs to only one or a few chunks. Inspired by rustc's SsoHashSet, keep these small memberships inline.In the main CodSpeed baseline,
connect_chunk_and_moduleaccounts for 7.14% of therust@build_chunk_graphsimulation profile; chunk-set insertion accounts for 3.85%, including 2.99% in hash-table growth.Changes
rspack_collections::SsoHashSet<T>, storing up to four elements inline and promoting toFxHashSeton the fifth distinct insertion. Chunk graph and plugin consumers useSsoHashSet<ChunkUkey>directly, without aModuleChunksalias. Large sets retain their allocation on removal/clear to avoid repeated promotion.Copy, non-Cloneelements by moving them during promotion. Add borrowed lookup/removal,Extend, andFromIterator.Cloneis needed to preserve memberships while mutating the graph and to retain independent concatenation snapshots; small clones do not allocate.shared.jsdirectly as its entry and validates memberships in compilation hooks, without a separate runtime test entry.Validation of the generic implementation (latest alias removal additionally rebuilt the binding and passed focused Clippy, formatting, 2 membership and 202 SplitChunks regression tests):
SsoHashSet<ChunkUkey>remains 32 bytes andChunkGraphModuleremains 96 bytes.Remote validation for
0372199completed successfully: PR CI, dispatched simulation and walltime CI, and the CodSpeed performance check passed.Latest CodSpeed comparison against main:
rust@build_chunk_graphrust@split_chunksrust@create_concatenate_modulebundle@threejs-10x-developmentbundle@threejs-10x-production-sourcemapThe latest PR simulation report contains 1 improvement, 49 untouched benchmarks, 47 skipped benchmarks, and no detected regressions. The combined simulation/walltime comparison contains 1 improvement and 96 untouched benchmarks, with no detected regressions. Simulation values are simulated timings, not elapsed walltime; the 3.58% improvement applies to the chunk-graph benchmark, not total bundling time.
Compared with the previous specialized implementation at
77e7d7c, all 97 benchmarks are classified untouched. Generalizing the collection and removing the aliases introduced no detected significant regression.CodSpeed flags different runtime environments for the comparison against main and identifies the self-hosted walltime environment as unknown, so small differences should be interpreted cautiously. The main comparison uses
d4cd073becausef077888has no benchmark run; their diff contains website files only.