perf: optimize ESM linking passes#14758
Conversation
|
📝 Benchmark detail: Open
Base persistent cache hit rate: 👍 Current persistent cache hit rate: 👍 |
📦 Binary Size-limit
🎉 Size decreased by 4.00KB from 66.50MB to 66.50MB (⬇️0.01%) |
Merging this PR will not alter performance
Comparing Footnotes
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
Pull request overview
This PR optimizes the ESM library linking pipeline in rspack_plugin_esm_library by removing redundant async work and avoiding repeated collection cloning during linking passes, reducing wall-clock time and allocation pressure in large module graphs.
Changes:
- Removed an unused per-module output-path resolution pass performed before parallel module analysis.
- Reworked namespace-object propagation to use an insertion-ordered worklist (index-based) instead of cloning the full set each iteration.
- Avoided cloning
hoisted_modulesduring link traversal by iterating by reference and copying identifiers only where needed.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Why
ESM linking performed async output-path resolution once per module and discarded every result. This added serial work on a high-cardinality structure before the parallel module analysis phase. Namespace propagation and hoisted-module traversal also cloned collections that can grow with the module graph.
The new flow preserves linking order and emitted output while removing those repeated computations and allocations.
Checks
pnpm run build:cli:devpnpm exec rstest EsmOutput.test.js(456 passed)cargo clippy -p rspack_plugin_esm_library --all-targets --all-featurescargo fmt --all --checkgit diff --checkpnpm run test:unit(9 host-contention timeout flakes; every timed-out case passed on isolated rerun)