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

Package on main thread for small rebuilds #8491

Closed
wants to merge 13 commits into from

Conversation

thebriando
Copy link
Member

@thebriando thebriando commented Sep 20, 2022

↪️ Pull Request

This change prevents WriteBundlesRequest from serializing across all workers with small rebuilds which should improve save/warm build times when small changes that only impact a single bundle are made to the project.

Tested saving a file with a small change in a large project

Before:

Save time ✨ Built in 154.08s
Packaging phase 13.614s

After:

Save time ✨ Built in 134.72s 🚀 12.56% faster
Packaging phase 1.948s 🚀 85.70% faster

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs


// Create shared reference in WorkerFarm if we need to change multiple bundles and if we
// can't skip the subrequests for all the bundles
if (
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if I got this logic quite right.. are there any other cases to look for here?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure either, but I'm confused that the comment says "can't skip all the bundles = at least 1 bundle can't be skipped" but then the if condition checks "there are at least 2 bundles which can't be skipped".

@parcel-benchmark
Copy link

parcel-benchmark commented Sep 20, 2022

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 1.39s +7.00ms
Cached 319.00ms -63.00ms 🚀

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

React HackerNews ✅

Timings

Description Time Difference
Cold 8.77s -18.00ms
Cached 428.00ms -1.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 1.47m +411.00ms
Cached 2.50s -70.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Three.js ✅

Timings

Description Time Difference
Cold 6.31s -92.00ms
Cached 266.00ms -17.00ms 🚀

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Click here to view a detailed benchmark overview.

@@ -1754,6 +1755,7 @@ export type PackagingProgressEvent = {|
+type: 'buildProgress',
+phase: 'packaging',
+bundle: NamedBundle,
+bundleGraph?: InternalBundleGraph,
Copy link
Member

Choose a reason for hiding this comment

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

  1. Do we really want to add the bundle graph to this event? (This is the public plugin API)
  2. If yes, then it certainly needs to be the public bundle graph type

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I think the main reason why I added this was because the ReporterRunner gets the BundleGraph from the WorkerFarm, which wouldn't exist in this case since we don't serialize the BundleGraph, so I sent the BundleGraph through the packaging/optimizing events.

let bundleGraph =
event.bundleGraph ??
this.workerFarm.workerApi.getSharedReference(
// $FlowFixMe
bundleGraphRef,
);
invariant(bundleGraph instanceof BundleGraph);

The invariant here also looks like it uses the private BundleGraph type?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should make an internal ReporterEvent type that has this instead?

@thebriando thebriando changed the title [WIP] Package on main thread for small rebuilds Package on main thread for small rebuilds Oct 25, 2022
Comment on lines +1771 to +1774
export type BundleGraphEvent = {|
+type: 'bundleGraph',
+bundleGraph: BundleGraph<NamedBundle>,
|};
Copy link
Member

Choose a reason for hiding this comment

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

What Devon meant in #8491 (comment) is that there could an internal event between PackagerRunner and ReporterRunner (which the reporter runner then just uses for setting the bundle graph but doesn't send it out to the reporter plugins).

But I think it's strange to have to split it up into two events in the first place.
Why don't you use the same idea of passing either the bundlegraph ref or the bundlegraph object itself in the packaging event? The PackagerRunnner is already running on the main thread, so calling report(something) wouldn't perform any serialization anyway.

@devongovett
Copy link
Member

I've refactored the WorkerFarm in a way that should make this a bit simpler to implement: #8589.

@mischnic mischnic deleted the bdo/single-thread-rebuild branch December 21, 2022 16:56
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.

None yet

4 participants