Skip to content

Improve module graph iteration performance#13072

Open
hardfist wants to merge 1 commit intomainfrom
codex/module-graph
Open

Improve module graph iteration performance#13072
hardfist wants to merge 1 commit intomainfrom
codex/module-graph

Conversation

@hardfist
Copy link
Contributor

  • Summary
    • swap existing .modules() and .modules().values() iterations for the faster modules_iter/dependencies_iter helpers and batch-update mutations directly via mutable references
    • streamline affected-module calculations by deduplicating incoming dependencies and using precomputed AffectType state for each referencing module
    • tighten async module traversal by collecting unique ESM targets before recursing
  • Testing
    • Not run (not requested)

Copilot AI review requested due to automatic review settings February 16, 2026 02:21
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Feb 16, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with modules_iter() to avoid intermediate collections.
  • Speed up affected-module computation by deduplicating incoming dependencies per referencing module and tracking AffectType incrementally.
  • 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.

Comment on lines +175 to +178
#[inline]
pub fn module_graph_modules_len(&self) -> usize {
self.inner.module_graph_modules.iter().count()
}
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 825.4 KB 0
rome 984.2 KB 0
react-5k 2.7 MB 0
ui-components 2.2 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Contributor

📦 Binary Size-limit

Comparing 221a375 to chore(deps): update dependency @playwright/test to v1.58.1 (#12874) by renovate[bot]

🎉 Size decreased by 26.00KB from 48.73MB to 48.71MB (⬇️0.05%)

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 16, 2026

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing codex/module-graph (221a375) with main (7f1665c)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant