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

Find more merge targets for experimentalMinChunkSize #5294

Merged
merged 5 commits into from Dec 11, 2023

Conversation

lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

This very much improves the merge algorithm for experimentalMinChunkSize when many dynamic imports are used. Previously, the side effect detection in the algorithm would not take into account whether a module was already in memory because it was a dependency of a dynamic importer.
This could lead to a sub-optimal situation where potentially a lot of possible merges were not applied. Take this example:

E is the entry point and has a side effect.
E dynamically imports D1 and D2.
E, D1, D2 all statically import a shared dependency S

Now the vanilla Rollup chunking algorithm has an optimization so that in this situation, it would merge S into E so that D1 and D2 import S from E. This is not a problem because we know E is in memory when either is loaded.

However this messed up experimentalMinChunkSize. Because E was not an explicit static dependency of either D1 or D2, merging either of these chunks would tell the algorithm that it would be bringing the side effect in E into a place where it was not a dependency before.

But of course this is not a problem because the effect in E was already executed long before either D1 or D2 was imported. This is fixed in this PR by leveraging the extended dynamic dependency information gathered in the original algorithm.

cc @gajus

Copy link

vercel bot commented Dec 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
rollup ✅ Ready (Inspect) Visit Preview Dec 10, 2023 8:41pm

Copy link

github-actions bot commented Dec 10, 2023

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#improve-minchunksize

Notice: Ensure you have installed Rust nightly. If you haven't installed it yet, please first see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust, then see https://rust-lang.github.io/rustup/concepts/channels.html to learn how to install Rust nightly.

or load it into the REPL:
https://rollup-349fqp4nw-rollup-js.vercel.app/repl/?pr=5294

Copy link

codecov bot commented Dec 10, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (098e29c) 98.82% compared to head (48ca140) 98.82%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5294   +/-   ##
=======================================
  Coverage   98.82%   98.82%           
=======================================
  Files         232      232           
  Lines        8957     8962    +5     
  Branches     2336     2336           
=======================================
+ Hits         8852     8857    +5     
  Misses         46       46           
  Partials       59       59           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lukastaegert lukastaegert merged commit 3a2b583 into master Dec 11, 2023
28 checks passed
@lukastaegert lukastaegert deleted the improve-minchunksize branch December 11, 2023 05:20
Copy link

This PR has been released as part of rollup@4.8.0. You can test it via npm install rollup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Many extra chunks are generated Possible chunk merges aren't applied
1 participant