Skip to content

Conversation

@JSerFeng
Copy link
Contributor

@JSerFeng JSerFeng commented Jan 9, 2026

Summary

RemoveDuplicatedModulesPlugin now supports using existing chunk as target splited chunk, but only works for chunk who has only one module.

Now you can use multiple single entry to hack preserveModules temporarily.

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings January 9, 2026 10:04
@JSerFeng JSerFeng requested a review from quininer as a code owner January 9, 2026 10:04
@netlify
Copy link

netlify bot commented Jan 9, 2026

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 683d716
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6960d535dfc06e00082e47cf

@github-actions github-actions bot added release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack. labels Jan 9, 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 enhances the RemoveDuplicateModulesPlugin to optimize chunk splitting by reusing existing chunks that contain only a single module, rather than always creating new chunks. This provides a temporary workaround for preserveModules functionality using multiple single entry points.

Key changes:

  • Modified the chunk deduplication algorithm to identify and reuse single-module chunks as target chunks for shared modules
  • Replaced FxHashMap with DashMap and added parallelization using rayon for improved performance when building the chunk map
  • Added skip logic to prevent splitting operations on reused chunks

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/rspack_plugin_remove_duplicate_modules/src/lib.rs Implements chunk reuse logic for single-module chunks and parallelizes chunk map construction
crates/rspack_plugin_remove_duplicate_modules/Cargo.toml Adds dashmap and rayon dependencies for concurrent processing
Cargo.lock Updates lock file with new dependency versions
tests/rspack-test/esmOutputCases/basic/single-entry-split/rspack.config.js Configures test with three entry points to trigger chunk reuse behavior
tests/rspack-test/esmOutputCases/basic/single-entry-split/index.js Main entry test file importing from foo module
tests/rspack-test/esmOutputCases/basic/single-entry-split/foo.js Intermediate module importing from bar
tests/rspack-test/esmOutputCases/basic/single-entry-split/bar.js Leaf module to be reused as single-module chunk
tests/rspack-test/esmOutputCases/basic/single-entry-split/__snapshots__/esm.snap.txt Expected output showing properly split chunks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mutations.add(Mutation::ChunkAdd {
chunk: new_chunk_ukey,
});
};
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

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

Unnecessary semicolon after the if-let block. In Rust, if blocks are expressions and don't need trailing semicolons when used as statements. This is also inconsistent with the similar if-let block at lines 86-91 which doesn't have a trailing semicolon. Consider removing this semicolon for consistency.

Suggested change
};
}

Copilot uses AI. Check for mistakes.
Comment on lines +51 to +54
let new_chunk_ukey = if let Some(chunk) = chunks.iter().find(|chunk| {
let chunk_modules = compilation.chunk_graph.get_chunk_modules_identifier(chunk);
chunk_modules.len() == 1
}) {
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

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

When using .find() to locate a reusable chunk, if multiple chunks have exactly 1 module, the implementation will pick the first one based on iteration order. Since chunks is sorted (line 38), this should be deterministic. However, it might be beneficial to add a comment explaining this behavior, or consider selecting based on a more explicit criterion (e.g., prefer entry chunks, or chunks with specific names) to make the selection strategy clearer.

Copilot uses AI. Check for mistakes.
@JSerFeng JSerFeng force-pushed the feat/remove-dup-modules-using-existing-chunk branch from 748500c to 683d716 Compare January 9, 2026 10:15
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

📦 Binary Size-limit

Comparing 683d716 to feat: add requireAlias option to control require variable renaming (#12686) by harpsealjs

❌ Size increased by 7.13KB from 47.88MB to 47.89MB (⬆️0.01%)

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

Labels

release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants