perf(core): defer top-level declaration flattening#13662
perf(core): defer top-level declaration flattening#13662LingyuCoder wants to merge 4 commits intomainfrom
Conversation
|
⏳ Triggered benchmark: Open |
Merging this PR will degrade performance by 5.12%🎉 Hooray!
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | rust@persistent_cache_restore@basic-react-development |
26.7 ms | 26.1 ms | +2.33% |
| ⚡ | Simulation | rust@persistent_cache_restore_after_single_file_change@basic-react-development |
28.1 ms | 27.5 ms | +2.28% |
| 🆕 | Simulation | rust@scan_dependencies@three_module |
N/A | 23.7 ms | N/A |
| ⚡ | Simulation | rust@concatenate_module_code_generation |
137.1 ms | 135 ms | +1.54% |
| ❌ | Simulation | rust@create_concatenate_module |
42.4 ms | 44.6 ms | -5.12% |
| ❌ | Simulation | rust@create_chunk_ids |
10.6 ms | 10.9 ms | -2.93% |
Comparing codex/top-level-declarations-multiple (b1a5b28) with main (6c9c5af)
Footnotes
-
19 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. ↩
Rsdoctor Bundle Diff Analysis
Found 6 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Pull request overview
This PR improves concatenated-module build performance by deferring eager flattening of top_level_declarations into a delayed TopLevelDeclarations representation, while updating downstream consumers to query “unknown/contains” without forcing a flatten step.
Changes:
- Introduce
TopLevelDeclarations(Unknown/Single/Multiple) and migrateBuildInfo.top_level_declarationsto it. - Update concatenated-module build to merge declaration sets without eager flattening (and parallelize some collection work).
- Update plugin consumers (library/runtime checks, JS parser meta info, inline-startup checks) to use
is_unknown()/contains()APIs.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rspack_core/src/module.rs | Adds TopLevelDeclarations and migrates BuildInfo.top_level_declarations to the new representation, plus unit tests. |
| crates/rspack_core/src/concatenated_module.rs | Refactors concatenated-module build to merge partials (including deferred top-level decls) and adds tests for merge behavior. |
| crates/rspack_core/src/external_module.rs | Initializes external modules with TopLevelDeclarations::Single(Default::default()). |
| crates/rspack_plugin_javascript/src/parser_plugin/javascript_meta_info_plugin.rs | Writes parser-discovered top-level decls via TopLevelDeclarations APIs. |
| crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs | Optimizes connection collection with parallel iteration; minor chunk-graph loop optimization. |
| crates/rspack_plugin_javascript/src/plugin/mod.rs | Updates inline-startup bailout logic to treat “unknown” top-level decls correctly. |
| crates/rspack_plugin_library/src/assign_library_plugin.rs | Updates runtime bailout logic to use TopLevelDeclarations semantics. |
| crates/rspack_plugin_mf/src/container/container_entry_module.rs | Initializes MF container entry modules with TopLevelDeclarations::Single(Default::default()). |
| crates/rspack_plugin_rsc/src/rsc_entry_module.rs | Initializes RSC entry modules with TopLevelDeclarations::Single(Default::default()). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 04518a4a16
ℹ️ 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".
📦 Binary Size-limit
❌ Size increased by 28.66KB from 49.35MB to 49.37MB (⬆️0.06%) |
|
📝 Benchmark detail: Open
|
Summary
top_level_declarationsflattening with a delayedTopLevelDeclarationsrepresentationUnknownsemantics while allowing concatenated modules to carry multiple declaration sets without merging them eagerlyWhy
The previous concatenated-module path eagerly merged large top-level declaration sets during build, which added noticeable cost to the hot path. This change defers flattening until it is actually needed and lets most callers operate on lightweight
contains/is_unknownchecks.Impact
ConcatenatedModule::buildValidation
cargo test -p rspack_core top_level_declarations --libcargo test -p rspack_core merge_concatenated_build_partials --libcargo check -p rspack_core -p rspack_plugin_javascript -p rspack_plugin_library -p rspack_plugin_rsc -p rspack_plugin_mfcargo fmt --all --checkpnpm run build:binding:devis blocked in this shell by the local Node.js version (v18.12.1); the branch is being published per user request after local verification