refactor(core): reduce concatenated module analysis overhead#13342
refactor(core): reduce concatenated module analysis overhead#13342LingyuCoder wants to merge 1 commit intomainfrom
Conversation
|
📝 Benchmark detail: Open No benchmark data for commit 3e83955, trying parent...
Threshold exceeded: ["10000_production-mode + exec","10000_production-mode_persistent-cold + exec","10000_production-mode_persistent-hot + exec","10000_production-mode_source-map + exec","threejs_production-mode_10x + exec","threejs_production-mode_10x_persistent-cold + exec","threejs_production-mode_10x_persistent-hot + exec"] |
There was a problem hiding this comment.
Pull request overview
Refactors concatenated-module analysis to reduce overhead and memory usage, with a focus on improving performance in large-module benchmarks.
Changes:
- Removes nested per-module async task fan-out during concatenated-module analysis.
- Stores
global_scope_identasswc_ecma_ast::Identinstead of a legacy wrapper type. - Avoids collecting/storing full
identsexcept whenmodern-modulelibrary builds require them.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/rspack_plugin_esm_library/src/link.rs | Updates ESM library linking logic to match the new global_scope_ident shape (Ident), minimizing cloning overhead. |
| crates/rspack_core/src/concatenated_module.rs | Refactors concatenation analysis flow, changes identifier storage to reduce work, and gates full ident materialization behind modern-module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let mut tmp = Vec::with_capacity(arc_map.len()); | ||
| for (id, info) in arc_map.iter() { | ||
| let concatenation_scope = if let ModuleInfo::Concatenated(info) = info { | ||
| Some(ConcatenationScope::new( | ||
| self.id, | ||
| arc_map.clone(), | ||
| info.as_ref().clone(), | ||
| )) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| let mut updated_pairs = vec![]; | ||
| for item in tmp { | ||
| updated_pairs.push(item?); | ||
| let updated_module_info = self | ||
| .analyze_module(compilation, info.clone(), runtime, concatenation_scope) | ||
| .await?; | ||
| tmp.push((*id, updated_module_info)); | ||
| } |
| async { | ||
| for (module_info_id, _) in references_info.iter() { | ||
| let Some(ModuleInfo::Concatenated(info)) = module_to_info_map.get_mut(module_info_id) | ||
| else { | ||
| continue; | ||
| }; | ||
| if info.has_ast { | ||
| all_used_names.extend(info.all_used_names.clone()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for (id, info) in module_to_info_map.iter_mut() { | ||
| if let ModuleInfo::Concatenated(info) = info { | ||
| compilation | ||
| .plugin_driver | ||
| .concatenated_module_hooks | ||
| .concatenated_info | ||
| .call(compilation, *id, runtime, info, &mut all_used_names) | ||
| .await?; | ||
| for (id, info) in module_to_info_map.iter_mut() { | ||
| if let ModuleInfo::Concatenated(info) = info { | ||
| compilation | ||
| .plugin_driver | ||
| .concatenated_module_hooks | ||
| .concatenated_info | ||
| .call(compilation, *id, runtime, info, &mut all_used_names) | ||
| .await?; | ||
| } | ||
| } | ||
| Ok::<(), Error>(()) | ||
| } | ||
| .await?; |
| fn concat_needs_all_idents(compilation: &Compilation) -> bool { | ||
| compilation | ||
| .options | ||
| .output | ||
| .enabled_library_types | ||
| .as_ref() | ||
| .is_some_and(|types| types.iter().any(|ty| ty == "modern-module")) |
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
🎉 Size decreased by 10.50KB from 49.04MB to 49.03MB (⬇️0.02%) |
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
Reduce
ConcatenatedModuleoverhead on therspack-ecosystem-benchmark/cases/10000case by:global_scope_identas plainIdentidentsformodern-modulelibrary builds, whererspack_plugin_esm_libraryactually needs themBenchmark
Case:
/Users/bytedance/rspack-dev/rspack-ecosystem-benchmark/cases/10000Local cold-run comparison with the same command shape (
NODE_DISABLE_COMPILE_CACHE=1,rm -rf dist, directRSPACK_BINDING):main: compile avg5.45s, real avg5.59s1.18s, real avg1.65sVerification
cargo fmt --allcargo check -p rspack_core -p rspack_plugin_esm_librarycases/10000Notes
cargo lintwas intentionally skipped at user request to speed up landing.