Find more merge targets for experimentalMinChunkSize #5294
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains:
Are tests included?
Breaking Changes?
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