Skip to content

Improve chunking algorithm for dynamic imports - #3354

Merged
lukastaegert merged 49 commits into
masterfrom
improve-chunking-dynamic-imports
Jan 27, 2020
Merged

lukastaegert merged 49 commits into
masterfrom
improve-chunking-dynamic-imports

Conversation

@lukastaegert

Copy link
Copy Markdown
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:
Resolves #3124

Description

This implements the algorithm outlined in #3124 to no longer split chunks if a dynamic import shares code with all its importing chunks. Instead in such a situation, it will import the relevant bindings from the existing chunks. This can noticeably reduce the number of created chunks for setups with many dynamic imports.
It will also fix issues with polyfills like this one: Here, even though the polyfill will load first before bundling, it will no longer load first after bundling because it is inlined into the main chunk while there is a separate chunk of code shared with the dynamic import that is loaded first.

After this fix is applied, this can no longer happen and in order to make sure a polyfill is loaded first, it is then sufficient to place it as first import in all static entry points (which is a necessary requirement anyway as the idea of static entry points is that they can be run in any order).

@lukastaegert
lukastaegert force-pushed the improve-chunking-dynamic-imports branch from d69d214 to 20813c0 Compare January 27, 2020 06:51
@codecov

codecov Bot commented Jan 27, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #3354 into master will increase coverage by 0.07%.
The diff coverage is 93.49%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3354      +/-   ##
==========================================
+ Coverage   93.18%   93.26%   +0.07%     
==========================================
  Files         172      172              
  Lines        6059     6071      +12     
  Branches     1804     1808       +4     
==========================================
+ Hits         5646     5662      +16     
+ Misses        220      218       -2     
+ Partials      193      191       -2
Impacted Files Coverage Δ
src/utils/entryHashing.ts 100% <ø> (+11.76%) ⬆️
src/utils/defaultPlugin.ts 94% <0%> (ø) ⬆️
src/ast/nodes/TaggedTemplateExpression.ts 63.63% <0%> (ø) ⬆️
src/utils/collapseSourcemaps.ts 90% <0%> (ø) ⬆️
src/Chunk.ts 93.97% <100%> (ø) ⬆️
src/ast/nodes/CallExpression.ts 95.41% <100%> (ø) ⬆️
src/finalisers/umd.ts 94.91% <100%> (ø) ⬆️
src/utils/PluginContext.ts 100% <100%> (ø) ⬆️
src/finalisers/iife.ts 100% <100%> (ø) ⬆️
src/ModuleLoader.ts 98.52% <100%> (ø) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 529a9a8...20813c0. Read the comment docs.

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.

Improve chunking algorithm for dynamic imports to recognize already loaded modules

2 participants