perf: optimize hot-path utility functions for large builds#21192
Conversation
Optimize comparators, StackedMap, BatchedHash, and deterministicGrouping based on CPU profiling of 10k-module builds with SplitChunks enabled. Key changes: - concatComparators: inline 2/3-arg fast paths, flat loop for 4+ - keepOriginalOrder: inline comparison to avoid function call overhead - compareNumbers: remove redundant type check (always receives numbers) - StackedMap: deduplicate has/get traversal via shared _lookup method - BatchedHash: local var caching, early Buffer check, charCodeAt - deterministicGrouping: for-in loops, avoid .slice() allocation
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #21192 +/- ##
==========================================
+ Coverage 92.70% 92.71% +0.01%
==========================================
Files 588 588
Lines 64091 64130 +39
Branches 17785 17796 +11
==========================================
+ Hits 59416 59459 +43
+ Misses 4675 4671 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 39.23%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "lodash", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
125.5 KB | 859.5 KB | -85.4% |
| ⚡ | Memory | benchmark "side-effects-reexport", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1,208.6 KB | 949.4 KB | +27.3% |
| ⚡ | Memory | benchmark "devtool-source-map", scenario '{"name":"mode-production","mode":"production"}' |
7.7 MB | 6.4 MB | +20.75% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing zakuru:perf/optimize-hot-path-utilities (220acb9) with main (8596a28)
|
Thanks for the detailed write-up and profiling effort here. We're going to close this one, but the safe ideas are worth carrying forward. Reasoning:
The genuinely safe micro-wins — the Generated by Claude Code |
|
thank you so much @alexander-akait ! |
Summary
Optimize four hot-path utility files based on CPU profiling of 10k-module builds (5 entries, SplitChunks enabled). The primary win is in
concatComparatorswhich is called in every sort operation during stats generation and chunk optimization — inlining 2/3-arg fast paths and using a flat loop for 4+ args avoids recursive rest-parameter array allocations. Additional micro-optimizations inkeepOriginalOrder,StackedMap,BatchedHash, anddeterministicGroupingreduce function call overhead and avoid unnecessary allocations on per-module hot paths.Measured 14.9% faster builds on a synthetic 10k-module benchmark with SplitChunks and stats generation enabled (1783ms vs 2049ms baseline).
What kind of change does this PR introduce?
perf
Did you add tests for your changes?
No new tests — existing test suite validates correctness (identical bundle output hash verified across all mutations).
Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a
Use of AI
AI (GPT-5.4 via OpenEvolve evolutionary optimization framework) was used to generate and evaluate candidate optimizations. Each mutation was validated against a correctness oracle (identical output bundle hash) before selection. Final review and integration done by human.