perf: optimize create chunk assets#14332
Conversation
There was a problem hiding this comment.
Pull request overview
This PR targets the create_chunk_assets compilation pass to reduce overhead when many assets are emitted, primarily by avoiding per-asset chunk_asset hook dispatch in the no-listener case and by reducing allocation churn when collecting parallel render results.
Changes:
- Preallocates storage for chunk render results before merging parallel
render_manifestoutputs. - Adds a fast path that batches per-chunk “rendered/files bookkeeping” and skips per-asset
chunk_assethook calls when the hook is empty. - Preserves the existing per-asset behavior when
chunk_assetis observed (taps/interceptors present).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
17409b2 to
f8d1a60
Compare
Merging this PR will not alter performance
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | js@collect imported identifiers |
222.4 µs | 228.6 µs | -2.71% |
| ⚡ | Simulation | rust@create_chunk_assets |
3.2 ms | 3 ms | +5.14% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing codex/perf-create-chunk-assets (96029d1) with main (b04d9f4)
Footnotes
-
40 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. ↩
📦 Binary Size-limit
❌ Size increased by 12.00KB from 62.60MB to 62.61MB (⬆️0.02%) |
f8d1a60 to
cb9013a
Compare
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
cb9013a to
5de5eb2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5de5eb2107
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
8bee73a to
253e4d6
Compare
253e4d6 to
96029d1
Compare
Summary
Round 6 for
rust@create_chunk_assetsreached the requested+5%target.chunk_assethook dispatch when the hook has no actual taps, including JS interceptor registrations that resolve to no tapsVecand avoid buildingChunkRenderArtifact/FxHashMapunless incremental chunk-asset caching is enabledVecinstead of hashing them into a set before render-manifest dispatch; incremental updates still dedupe affected chunkschunk_assetfast path from the hooked path so the common path avoids a per-chunk hook-state branchchunk_assetis observed by Rust or JS pluginsExpected performance mechanism
The create chunk assets stage can emit many chunk assets. In the common full-build no-listener path, this avoids hash-set construction for the chunk list, resolves chunk asset taps once for the pass, avoids an async hook call per emitted file, avoids full-build hash-map/artifact construction, reduces small Vec growth while collecting render manifests, skips empty diagnostics merging, batches chunk rendered/file bookkeeping per chunk, and keeps the hot no-hook loop separate from the compatibility hook loop.
Validation
CI-only workflow: local build, test, lint, and benchmark commands were not run.
cargo fmt --allwas run only to apply formatting after CI reported a rustfmt diff in an earlier round.Round 6 head:
96029d1fd1c71b1361f3a5b80db73e5febb80df9.GitHub Actions for this head passed:
CodSpeed for this head reported:
rust@create_chunk_assets:3.2 ms->3 ms,+5.14%js@collect imported identifiers:222.4 us->228.6 us,-2.71%CodSpeed also reported Walltime/runtime-environment warnings, so the exact percentages should be read with that context. Binary size-limit reported
+12.00KB/+0.02%for this head.