-
-
Notifications
You must be signed in to change notification settings - Fork 754
feat: RemoveDuplicatedModulesPlugin supports using existing modules for chunk who has only 1 module #12690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for rspack canceled.
|
There was a problem hiding this 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
FxHashMapwithDashMapand added parallelization usingrayonfor 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, | ||
| }); | ||
| }; |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
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.
| }; | |
| } |
| 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 | ||
| }) { |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
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.
…or chunk who has only 1 module
748500c to
683d716
Compare
📦 Binary Size-limit
❌ Size increased by 7.13KB from 47.88MB to 47.89MB (⬆️0.01%) |
Summary
RemoveDuplicatedModulesPluginnow 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
preserveModulestemporarily.Related links
Checklist