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

Recursively check reachability when removing asset graphs from bundles in deduplication #6004

Merged
merged 14 commits into from
Jan 3, 2023

Conversation

gorakong
Copy link
Contributor

@gorakong gorakong commented Mar 16, 2021

↪️ Pull Request

Fixes some No reachable bundle found containing... errors that occur in scope-hoisted builds.

image

Before:
During sibling deduplication, unreachable is first removed from Shared Bundle 2 because it is reachable via its sibling bundle (Shared Bundle 1). common (and its subgraph) is then removed from Shared Bundle 1 because it is reachable via Shared Bundle 2. As a result, unreachable is no longer in any of the bundleGroups Shared Bundle 1 is in (thereby becoming unreachable from Shared Bundle 1).

After:
Recursively check reachability when removing asset graphs from bundles in deduplication.

Will be checking to see if this addresses #5770

✔️ PR Todo

  • Added integration tests for both scope-hoisted and non-scope-hoisted builds
  • Assessed performance implications on a large app:

Optimizing (avg time)
Before: 3.62s
After: 13.21s
265% slower

Bundling (avg time)
Before: 19.46s
After: 36.70s
88.6% slower

Overall build time, avg:
Before: 438s
After: 464s
5.9% slower

@height
Copy link

height bot commented Mar 16, 2021

Link Height tasks by mentioning a task ID in the pull request title or description, commit messages, or comments.

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

@parcel-benchmark
Copy link

parcel-benchmark commented Mar 16, 2021

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 1.83s +32.00ms
Cached 391.00ms -2.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 324.00ms +26.00ms ⚠️
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 326.00ms +27.00ms ⚠️
dist/modern/parcel.7cdb0fad.webp 102.94kb +0.00b 325.00ms +26.00ms ⚠️
dist/legacy/index.2c76ad23.js 1.66kb +0.00b 539.00ms +41.00ms ⚠️
dist/legacy/index.8aaa89c9.js 1.20kb +0.00b 539.00ms +41.00ms ⚠️
dist/modern/index.6be20f01.js 1.13kb +0.00b 538.00ms +40.00ms ⚠️
dist/legacy/index.html 826.00b +0.00b 687.00ms +60.00ms ⚠️
dist/modern/index.html 749.00b +0.00b 685.00ms +60.00ms ⚠️
dist/legacy/index.b8ae99ba.css 94.00b +0.00b 334.00ms +28.00ms ⚠️
dist/modern/index.31cedca9.css 94.00b +0.00b 333.00ms +28.00ms ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 294.00ms +195.00ms ⚠️
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 295.00ms +195.00ms ⚠️
dist/modern/parcel.7cdb0fad.webp 102.94kb +0.00b 295.00ms +195.00ms ⚠️

React HackerNews ✅

Timings

Description Time Difference
Cold 11.53s -17.00ms
Cached 513.00ms -11.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 2.01m +1.40s
Cached 2.73s +155.00ms ⚠️

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Three.js ✅

Timings

Description Time Difference
Cold 8.62s -53.00ms
Cached 322.00ms -13.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Click here to view a detailed benchmark overview.

@gorakong gorakong changed the title Do not deduplicate an asset if it will become unreachable Recursively check reachability when removing asset graphs from bundles in deduplication Mar 18, 2021
@gorakong gorakong marked this pull request as ready for review March 18, 2021 21:12
@@ -435,7 +438,11 @@ function deduplicate(bundleGraph: MutableBundleGraph) {
bundle.hasAsset(asset) &&
bundleGraph.isAssetReachableFromBundle(asset, bundle)
) {
bundleGraph.removeAssetGraphFromBundle(asset, bundle);
if (isSiblingDedupe) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be treating these differently

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@wbinnssmith wbinnssmith Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense — they're no longer reachable because the context changes across those sibling bundles. Let's get #5398 landed, which includes support for multiple contexts per environment [0], which will allow these cross-context shared bundles to have both contexts.

Removal should always be implemented in one way though.

cc @devongovett

[0] https://github.com/parcel-bundler/parcel/pull/5398/files#diff-b2e31de6fe476821294b35d7fb17106cf1fc48b37ebe5800448dcb3608348b6cR774

@mischnic
Copy link
Member

mischnic commented Dec 21, 2022

The test cases pass with the current v2 branch. Should we add the test cases (without the outdated fix) though? @gorakong @AGawrys @devongovett

@gorakong
Copy link
Contributor Author

@mischnic sounds good to me! i've updated the PR to only include the test cases.

@mischnic
Copy link
Member

Looks like you removed too much, these actual tests are missing now:

diff --git packages/core/integration-tests/test/javascript.js packages/core/integration-tests/test/javascript.js
index bceb92c15..22b92cf59 100644
--- packages/core/integration-tests/test/javascript.js
+++ packages/core/integration-tests/test/javascript.js
@@ -6242,6 +6215,23 @@ describe('javascript', function () {
     assert.deepEqual(o2, ['UIIcon', 'Icon']);
   });
 
+  it('should not deduplicate an asset if it will become unreachable', async function () {
+    let b = await bundle(
+      path.join(
+        __dirname,
+        'integration/sibling-deduplicate-unreachable/index.js',
+      ),
+      {
+        mode: 'production',
+        defaultTargetOptions: {
+          shouldScopeHoist: false,
+        },
+      },
+    );
+    let res = await run(b);
+    assert.equal(await res.default, 'target');
+  });
+
   for (let shouldScopeHoist of [false, true]) {
     let options = {
       defaultTargetOptions: {
diff --git packages/core/integration-tests/test/scope-hoisting.js packages/core/integration-tests/test/scope-hoisting.js
index 985d5b672..0c22614ba 100644
--- packages/core/integration-tests/test/scope-hoisting.js
+++ packages/core/integration-tests/test/scope-hoisting.js
@@ -5586,4 +5586,16 @@ describe('scope hoisting', function () {
       await workerFarm.end();
     }
   });
+
+  it('should not deduplicate an asset if it will become unreachable', async function() {
+    let b = await bundle(
+      path.join(
+        __dirname,
+        'integration/sibling-deduplicate-unreachable/index.js',
+      ),
+      {mode: 'production'},
+    );
+    let res = await run(b);
+    assert.equal(res, 'target');
+  });
 });

@gorakong
Copy link
Contributor Author

gorakong commented Jan 2, 2023

@mischnic oops good catch! i've added them back 😅

@mischnic mischnic merged commit b82f592 into v2 Jan 3, 2023
@mischnic mischnic deleted the unreachable-asset branch January 3, 2023 21:17
marcins pushed a commit to marcins/parcel that referenced this pull request Jul 14, 2023
* upstream/v2: (33 commits)
  v2.8.3
  Changelog for v2.8.3
  Address bug by updating an asset reference and merge conditions (parcel-bundler#8762)
  Fix CSS order when merging type change bundles (parcel-bundler#8766)
  fixing failing build for contributors on Linux using Node 18 (parcel-bundler#8763)
  Extension: Importers View and separate LSP protocol package (parcel-bundler#8747)
  Bump swc to fix sourcemaps with Windows line endings (parcel-bundler#8756)
  Apply HMR updates in topological order (parcel-bundler#8752)
  Make extension packaging work (parcel-bundler#8730)
  Typed api.storeResult (parcel-bundler#8732)
  Refactor LSP to use vscode-jsonrpc (parcel-bundler#8728)
  Bump swc (parcel-bundler#8742)
  Recursively check reachability when removing asset graphs from bundles in deduplication (parcel-bundler#6004)
  Fix tsc sourcemaps metadata (parcel-bundler#8734)
  Assigning to `this` in CommonJS (parcel-bundler#8737)
  Don't retarget dependencies if a symbol is imported multiple times with different local names (parcel-bundler#8738)
  Add a note about using flow in CONTRIBUTING.md (parcel-bundler#8731)
  filter out title execArgv to workers (parcel-bundler#8719)
  Document more of the BundleGraph class (parcel-bundler#8711)
  Fixed the hmr connection with host 0.0.0.0 (parcel-bundler#7357)
  ...
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.

4 participants