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

Assetgraph propagate symbols #4861

Merged
merged 83 commits into from
Nov 18, 2020
Merged

Assetgraph propagate symbols #4861

merged 83 commits into from
Nov 18, 2020

Conversation

mischnic
Copy link
Member

@mischnic mischnic commented Jul 8, 2020

↪️ Pull Request

Supersedes #4841
Closes #4565

Closes T-675

  • After building the asset graph, propagate symbols in two passes (up & down). This is faster than doing it while building the asset graph because the bookkeeping (many nodes are visited multiple times) brings too much overhead.

  • Use asset.usedSymbols information to:

    • exclude JS assets in the JSPackager
    • When exposing an asset to a different bundle (so shared bundles are shaken as well)
  • Use dependency.usedSymbols information to:

    • Skip unused subgraphs in the bundler. So bundles for unused imports aren't even created and CSS imports from excluded assets are excluded as well (but sideEffects: ["*.css"] is usually required to get any CSS at all).
      • This condition (currently hardcoded in the BundleGraph) should really be exposed to the bundler!
    • This essentially behaves just like deferring the assets, but still excludes these files if deferring deopts (chained reexports / namespace)
  • We now need to check for missing exports in the AssetGraphBuilder, because when importing a missing symbol would mean that no symbols in that subgraph are actually used and the subgraph is removed entirely. The packager wouldn't be able to differentiate between "asset is missing because an import was wrong" and "asset is missing because it was unused & excluded". So resolving symbols essentially happens not when replacing the used import but when resolving the dependency, this might cause problems for TS's "phantom" imports? This could be alleviated by not adding a symbol to the dependency when hoisting if it's not actually referenced in the asset.

Follow up tasks:

  1. Tree shaking dynamic imports
  2. Somehow operate on symbols cross assets (e.g. skip TS type reexports)
  3. actually do the symbol resolution in the graph (not sure how slower this would be). Could catch conflicting reexports (to be spec compliant)

✔️ PR Todo

  • Update two tests in html.js
  • Test TS imports? (Stray type imports that weren't removed during transpilation)
  • make this.propagateSymbols() incremental (only update when assets changed)

Complete Benchmark

v2, cold cache
	191.35s user 28.42s system 374% cpu 58.626 total
    196.22s user 30.34s system 372% cpu 1:00.84 total
 	178.72s user 27.41s system 374% cpu 55.096 total
 gdu -sB1 dist
	16654336	dist


v2, no changes:
	9.48s user 1.45s system 213% cpu 5.123 total
	11.49s user 1.80s system 213% cpu 6.234 total
	10.27s user 1.59s system 209% cpu 5.653 total

v2, cold cache, minify:
	271.32s user 34.83s system 328% cpu 1:33.24 total
 	270.44s user 33.86s system 331% cpu 1:31.82 total
  gdu -sB1 dist
	5873664	dist

-------

propagate, cold cache:
	190.78s user 28.86s system 380% cpu 57.648 total
	182.22s user 28.42s system 370% cpu 56.867 total
	180.72s user 28.06s system 375% cpu 55.613 total
 gdu -sB1 dist
	16289792	dist

propagate, no changes:
	9.76s user 1.49s system 211% cpu 5.310 total
	10.63s user 1.62s system 208% cpu 5.880 total
	10.38s user 1.59s system 208% cpu 5.752 total

propagate, cold cache, minify:
	254.50s user 31.51s system 304% cpu 1:33.88 total
	251.15s user 30.40s system 343% cpu 1:21.97 total
 	248.30s user 31.13s system 338% cpu 1:22.67 total
	243.36s user 30.87s system 344% cpu 1:19.71 total
 gdu -sB1 dist
	5672960	dist

Benchmark (while determining which strategy to use)

Times in ms

ak-editor$ parcel2 build . --no-minify --no-source-maps

baseline: not incremental:

main   : 700, 834, 683, 757
runtime:  30,  26,  22,  25

baseline: without the topological ordering:

main   : 309, 361
runtime:  18,  21

current: incremental, cold cache:

main

down: 249, 246, 213, 227
up  :  92,  64,  65,  69

runtime

down:   6,  17,   7,   4
up  :   2,   2,   3,   2

current: incremental, no change

main

down: 40, 38, 39
up  : 61, 58, 58

"up" is slow because of getIncomingDependencies

@height
Copy link

height bot commented Jul 8, 2020

This pull request has been linked to and will mark 1 task as "Done" when merged:

💡Tip: You can link multiple Height tasks to a pull request.

@mischnic mischnic force-pushed the assetgraph-propagate-symbols-fast branch from 244f060 to 85c7a04 Compare July 8, 2020 17:37
@mischnic mischnic changed the title Assetgraph propagate symbols fast Assetgraph propagate symbols Jul 8, 2020
@mischnic mischnic marked this pull request as ready for review July 8, 2020 18:49
@mischnic mischnic force-pushed the assetgraph-propagate-symbols-fast branch 2 times, most recently from 1618e41 to 8047131 Compare July 11, 2020 15:52
@mischnic mischnic force-pushed the assetgraph-propagate-symbols-fast branch from 8047131 to 2ddbc64 Compare July 13, 2020 21:46
@mischnic mischnic mentioned this pull request Jul 15, 2020
5 tasks
@mischnic mischnic force-pushed the assetgraph-propagate-symbols-fast branch from 8ebd1e5 to 17fa612 Compare August 7, 2020 14:17
@mischnic mischnic merged commit 04b47e1 into v2 Nov 18, 2020
@mischnic mischnic deleted the assetgraph-propagate-symbols-fast branch November 18, 2020 22:57
gorakong pushed a commit that referenced this pull request Nov 18, 2020
Co-authored-by: Will Binns-Smith <wbinnssmith@atlassian.com>
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.

Parcel2 v. Webpack - parcel bundle size is significantly larger
3 participants