Skip to content
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

feat(new_split_chunks): support reuseExistingChunk #3000

Merged
merged 3 commits into from
May 4, 2023
Merged

Conversation

hyf0
Copy link
Collaborator

@hyf0 hyf0 commented May 4, 2023

Related issue (if exists)

Related to #2991, but I need to add a test case for it in another PR to make sure solving the issue.

Summary

With reuseExistingChunk: true, Rspack would try to reuse chunks generated in CodeSplitting.

The test case reuse-existing-chunk-simple shows that the splittedFoo chunk is the same as foo_js chunk(generated in CodeSplitting), so we could just reuse the foo_js chunk instead of creating a new splittedFoo chunk.

🤖 Generated by Copilot at 5eff55d

This pull request adds a new option reuseExistingChunk to the split chunks plugin, which allows reusing existing chunks with the same modules instead of creating new ones. This option is enabled by default to improve performance and reduce bundle size. The pull request modifies the rspack_plugin_split_chunks_new crate and the rspack package to implement and expose the option. It also enables the let_chains feature in the rspack_plugin_split_chunks_new crate.

Walkthrough

🤖 Generated by Copilot at 5eff55d

  • Add a new option reuseExistingChunk to the cache group configuration, which controls whether to reuse an existing chunk if it contains the same modules as the current chunk (link, link, link)
  • Pass the value of the reuseExistingChunk option to the CacheGroup and ModuleGroup structs, which represent the cache group and the module group in the plugin logic (link, link, link)
  • Enable the let_chains feature in the rspack_plugin_split_chunks_new crate, which allows using let expressions in the condition of an if or while statement (link)
  • Import std::borrow::Cow to create a borrowed or owned reference to the chunks that the module group is related to (link)
  • Modify the get_corresponding_chunk method in the plugin.rs file, which finds or creates a new chunk for a module group, to check if there is a reusable chunk and reuse it if the reuseExistingChunk option is true (link, link)
  • Add a new method find_the_best_reusable_chunk in the plugin.rs file, which searches for the best existing chunk that can be reused for a module group based on the chunk name and the modules (link)
  • Set the default value of the reuseExistingChunk option to true when converting a SplitChunksCacheGroup to a RawSplitChunksCacheGroup (link)

@hyf0 hyf0 requested a review from ahabhgk May 4, 2023 04:54
@hyf0 hyf0 requested review from hardfist and h-a-n-a as code owners May 4, 2023 04:54
@changeset-bot
Copy link

changeset-bot bot commented May 4, 2023

🦋 Changeset detected

Latest commit: 5eff55d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@rspack/binding Patch
@rspack/postcss-loader Patch
@rspack/core Patch
webpack-test Patch
@rspack/cli Patch
@rspack/dev-middleware Patch
@rspack/dev-server Patch
@rspack/plugin-html Patch
benchmarkcase-rspack-react-refresh Patch
@rspack/dev-client Patch
@rspack/plugin-minify Patch
@rspack/plugin-node-polyfill Patch
@rspack/binding-darwin-arm64 Patch
@rspack/binding-darwin-x64 Patch
@rspack/binding-linux-x64-gnu Patch
@rspack/binding-win32-x64-msvc Patch
@rspack/fs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added release: feature team The issue/pr is created by the member of Rspack. labels May 4, 2023
@hyf0 hyf0 added this pull request to the merge queue May 4, 2023
Merged via the queue into main with commit e5d33eb May 4, 2023
@hyf0 hyf0 deleted the hyf_23849023890482 branch May 4, 2023 07:13
This was referenced May 9, 2023
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.

2 participants