Conversation
There was a problem hiding this comment.
Pull request overview
This PR optimizes hot-path iteration patterns over the module graph by switching from allocating .modules()/.values()/.keys() maps to using iterator helpers directly, and by reducing repeated work during affected-module and async-module traversal.
Changes:
- Replace several
modules().values()/keys()iterations withmodules_iter()to avoid intermediate collections. - Speed up affected-module computation by deduplicating incoming dependencies per referencing module and tracking
AffectTypeincrementally. - Tighten async module traversal by collecting unique ESM outgoing targets before recursing.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/rspack_core/src/runtime_template.rs | Deduplicates ESM outgoing targets before recursing in async-module traversal. |
| crates/rspack_core/src/module_graph/mod.rs | Adds iterator/len helpers and switches batch updates to mutate connections/modules in place. |
| crates/rspack_core/src/incremental/mutations.rs | Streamlines affected-module calculation using per-referencing-module dedup + incremental AffectType aggregation. |
| crates/rspack_core/src/compilation/module_ids/mod.rs | Uses modules_iter() to avoid allocating a temporary modules map. |
| crates/rspack_core/src/compilation/build_module_graph/graph_updater/cutout/mod.rs | Uses modules_iter() + then_some for cleaner/faster filtering of rebuild-needed modules. |
| crates/rspack_core/src/compilation/build_chunk_graph/mod.rs | Uses modules_iter() to gather module identifiers without building an intermediate map. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #[inline] | ||
| pub fn module_graph_modules_len(&self) -> usize { | ||
| self.inner.module_graph_modules.iter().count() | ||
| } |
There was a problem hiding this comment.
module_graph_modules_len() currently computes the size by iterating and counting (iter().count()), which is O(n) and can be surprisingly expensive (especially with overlays). Since the method name implies a cheap length lookup, consider either implementing a real len() on rollback::OverlayMap (e.g., base.len() plus/minus overlay tombstones, O(overlay)) and calling that here, or renaming/documenting this as an O(n) count to avoid misuse in hot paths.
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 26.00KB from 48.73MB to 48.71MB (⬇️0.05%) |
Merging this PR will not alter performance
Comparing Footnotes
|
.modules()and.modules().values()iterations for the fastermodules_iter/dependencies_iterhelpers and batch-update mutations directly via mutable references