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

Packager request #6379

Merged
merged 17 commits into from Jun 10, 2021
Merged

Packager request #6379

merged 17 commits into from Jun 10, 2021

Conversation

devongovett
Copy link
Member

@devongovett devongovett commented May 31, 2021

Depends on #6373. Closes T-764 T-765. Fixes #5755

This refactors packaging and optimizing into requests like everything else in Parcel, and adds invalidations to the request graph for everything that might cause us to need to repackage/optimize. This includes dev dependencies, config, options, etc.

In addition to packaging and optimizing, the process of writing each bundle to the dist directory is also a request now, which means we avoid the work of writing bundles to dist that haven't changed. This also tracks if the dist file was deleted manually by the user and rewrites it if needed.

Finally, the entire Parcel build process is now a request as well. Rather than the Parcel class calling each step, there is a single ParcelBuildRequest that treats each of these steps as sub-requests. This ensures that old sub-requests get deleted from the request graph properly instead of leaking orphaned nodes.

@height
Copy link

height bot commented May 31, 2021

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

@@ -1458,7 +1450,9 @@ export default class BundleGraph {

getHash(bundle: Bundle): string {
let hash = new Hash();
hash.writeString(bundle.id + this.getContentHash(bundle));
hash.writeString(
bundle.id + bundle.target.publicUrl + this.getContentHash(bundle),
Copy link
Member Author

Choose a reason for hiding this comment

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

Target options aren't in the environment hash and aren't tracked in the graph. This is kinda assuming that packagers will use the publicUrl in some way, but currently this is only true of the HTML packager. Perhaps we can make this more granular in the future somehow...


await this.#packagerRunner.writeBundles(bundleGraph);
assertSignalNotAborted(signal);
} = await this.#requestTracker.runRequest(request, {force: true});
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently we force the parcel build request to run every time, even when nothing changed. This doesn't cause the sub-requests to re-run – they will return cached results. But if we want to emit a build success event with the bundle graph for builds where nothing actually changed, we need to do this to get the results.

Copy link
Member

@mischnic mischnic Jun 9, 2021

Choose a reason for hiding this comment

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

Could the the parcel build request do api.storeResult instead of only returning it? Not sure if that's more overhead than just rerunning

}

_getOptimizerNodes(
filePath: FilePath,
pipeline: ?string,
): PureParcelConfigPipeline {
// If a pipeline is specified, but it doesn't exist in the optimizers config, ignore it.
// Pipelines for bundles come from their entry assets, so the pipeline likely exists in transformers.
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes #5755

@@ -282,7 +283,26 @@ export class PackagedBundle extends NamedBundle implements IPackagedBundle {
return packagedBundle;
}

static getWithInfo(
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't get Flow to let me add an additional argument to the existing get function...

// Watch the bundle and source map for deletion.
// Also watch the dist dir because invalidateOnFileDelete does not currently
// invalidate when a parent directory is deleted.
// TODO: do we want to also watch for file edits?
Copy link
Member Author

Choose a reason for hiding this comment

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

I thought it might be weird if a user wanted to manually edit a file in the dist directory for some reason (e.g. debugging), and Parcel immediately overwrote it

/**
* Packages, optimizes, and writes all bundles to the dist directory.
*/
export default function createWriteBundlesRequest(
Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a better name for this request? It's very similar to the singular WriteBundleRequest. This one does the entire process of packaging, optimizing, and writing every bundle. Open to name suggestions here.

get filePath(): string {
return nullthrows(this.#bundle.filePath);
return nullthrows(this.#bundleInfo).filePath;
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously, we mutated the bundle after packaging to set the file path we actually wrote to. This has a number of problems with caching, so I moved this to a separate bundle info object. It's transparent to the end user, but internally, this is not stored on the actual bundle node.

@devongovett
Copy link
Member Author

One other question is how granular we want to get. Right now, packaging and optimizing a bundle is a single request, and they are cached together, but we could make the separate requests if we wanted.

@parcel-benchmark
Copy link

parcel-benchmark commented May 31, 2021

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 1.73s +270.00ms ⚠️
Cached 287.00ms -85.00ms 🚀

Cold Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 545.00ms -143.00ms 🚀
dist/modern/parcel.7cdb0fad.webp 102.94kb +0.00b 546.00ms -143.00ms 🚀
dist/legacy/index.html 701.00b +0.00b 906.00ms +181.00ms ⚠️
dist/modern/index.html 701.00b +0.00b 906.00ms +182.00ms ⚠️
dist/legacy/index.232649b1.css 77.00b +0.00b 1.03s +308.00ms ⚠️
dist/modern/index.ba69737b.css 77.00b +0.00b 1.03s +308.00ms ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 509.00ms +467.00ms ⚠️
dist/modern/parcel.7cdb0fad.webp 102.94kb +0.00b 509.00ms +442.00ms ⚠️
dist/legacy/index.8a81a4b4.js 2.00kb +0.00b 810.00ms +742.00ms ⚠️
dist/modern/index.a053a4c6.js 2.00kb +0.00b 809.00ms +741.00ms ⚠️
dist/legacy/index.html 701.00b +0.00b 900.00ms +833.00ms ⚠️
dist/modern/index.html 701.00b +0.00b 900.00ms +832.00ms ⚠️
dist/legacy/index.232649b1.css 77.00b +0.00b 1.02s +951.00ms ⚠️
dist/modern/index.ba69737b.css 77.00b +0.00b 1.02s +950.00ms ⚠️

React HackerNews ✅

Timings

Description Time Difference
Cold 9.57s +5.00ms
Cached 446.00ms -168.00ms 🚀

Cold Bundles

Bundle Size Difference Time Difference
dist/logo.1e014c76.png 274.00b +0.00b 269.00ms -4.34s 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/index.js 491.05kb +0.00b 5.51s +5.43s ⚠️
dist/PermalinkedComment.4bc80878.js 4.19kb +0.00b 5.51s +5.43s ⚠️
dist/UserProfile.f83d252c.js 1.56kb +0.00b 5.51s +5.43s ⚠️
dist/NotFound.c41ac89d.js 417.00b +0.00b 5.51s +5.43s ⚠️
dist/logo.1e014c76.png 274.00b +0.00b 283.00ms +232.00ms ⚠️

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 1.14m +2.61s
Cached 1.74s -1.03s 🚀

Cold Bundles

Bundle Size Difference Time Difference
dist/index.d7db16b9.js 2.60mb -20.00b 🚀 26.72s +943.00ms
dist/pdfRenderer.82551541.js 411.56kb +0.00b 44.40s -6.71s 🚀
dist/popup.9a91b047.js 209.85kb +0.00b 44.40s -6.71s 🚀
dist/media-viewer.1124ac09.js 74.99kb +0.00b 44.40s -6.71s 🚀
dist/card.0a49c739.js 62.67kb +0.00b 44.40s -6.71s 🚀
dist/card.d2e1fdad.js 60.71kb +0.00b 44.40s -6.73s 🚀
dist/esm.6a911099.js 33.24kb +0.00b 44.40s -6.71s 🚀
dist/ui.bf7534af.js 14.94kb +0.00b 44.40s -6.71s 🚀
dist/dropzone.4f0664ea.js 12.15kb +0.00b 44.40s -6.71s 🚀
dist/card.4cdca260.js 5.96kb +0.00b 44.40s -6.71s 🚀
dist/EmojiPickerComponent.0659235c.js 3.72kb +0.00b 44.40s -6.71s 🚀
dist/dropzone.e14c32d9.js 3.29kb +0.00b 44.40s -6.71s 🚀
dist/clipboard.d13fb601.js 2.93kb +0.00b 44.40s -6.73s 🚀
dist/ResourcedEmojiComponent.a1d3f4a0.js 2.12kb +0.00b 44.40s -6.71s 🚀
dist/browser.7f2c1dda.js 1.69kb +0.00b 44.40s -6.73s 🚀
dist/workerHasher.c8ca1949.js 1.63kb +0.00b 44.40s -6.71s 🚀
dist/heading6.43c4a239.js 1.51kb +0.00b 26.93s -15.24s 🚀
dist/heading3.86883cea.js 1.49kb +0.00b 26.93s -15.24s 🚀
dist/heading5.eead537b.js 1.38kb +0.00b 26.93s -15.24s 🚀
dist/expand.44b4643e.js 1.29kb +0.00b 44.40s +2.23s ⚠️
dist/heading4.cc81126f.js 1.27kb +0.00b 26.93s -15.24s 🚀
dist/media-card-analytics-error-boundary.e1f2c03b.js 1.12kb +0.00b 44.40s -6.71s 🚀
dist/media-viewer-analytics-error-boundary.b7edd41f.js 964.00b +0.00b 44.40s -6.71s 🚀
dist/media-picker-analytics-error-boundary.f598f6fd.js 964.00b +0.00b 44.40s -6.71s 🚀
dist/media-card-analytics-error-boundary.ca13875d.js 960.00b +0.00b 44.40s -6.71s 🚀
dist/simpleHasher.db850807.js 641.00b +0.00b 44.40s -6.71s 🚀
dist/index.html 119.00b +0.00b 44.41s +22.66s ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/index.cdcf98d2.js 2.60mb +11.00b ⚠️ 26.98s +26.87s ⚠️
dist/pdf.worker.44fcec94.js 727.98kb +0.00b 45.06s +44.90s ⚠️
dist/editorView.19ca0f5a.js 594.99kb +0.00b 54.55s +54.38s ⚠️
dist/pdfRenderer.82551541.js 411.56kb +0.00b 53.94s +53.78s ⚠️
dist/popup.9a91b047.js 209.85kb +0.00b 53.94s +53.77s ⚠️
dist/EmojiPickerComponent.8fb44bf0.js 147.28kb +0.00b 53.94s +53.81s ⚠️
dist/Toolbar.c83228e9.js 107.27kb +0.00b 54.55s +54.38s ⚠️
dist/media-viewer.1124ac09.js 74.99kb +0.00b 53.94s +53.78s ⚠️
dist/card.0a49c739.js 62.67kb +0.00b 53.94s +53.79s ⚠️
dist/card.d2e1fdad.js 60.71kb +0.00b 54.04s +53.87s ⚠️
dist/Modal.c0a88dab.js 45.33kb +0.00b 26.91s +26.75s ⚠️
dist/component.cac2fecd.js 37.59kb +0.00b 26.91s +26.75s ⚠️
dist/esm.6a911099.js 33.24kb +0.00b 53.94s +53.81s ⚠️
dist/component.70d0429c.js 24.95kb +0.00b 26.91s +26.76s ⚠️
dist/DatePicker.2195ca9d.js 22.99kb +0.00b 45.06s +44.93s ⚠️
dist/js.82b1c3de.js 17.33kb +0.00b 26.65s +26.49s ⚠️
dist/ui.bf7534af.js 14.94kb +0.00b 53.94s +53.79s ⚠️
dist/smartMediaEditor.27f41748.js 13.25kb +0.00b 54.55s +54.38s ⚠️
dist/dropzone.4f0664ea.js 12.15kb +0.00b 54.04s +53.87s ⚠️
dist/workerHasher.f2448c7e.js 11.81kb +0.00b 45.06s +44.93s ⚠️
dist/component.4e8fd03c.js 6.82kb +0.00b 26.65s +26.49s ⚠️
dist/card.4cdca260.js 5.96kb +0.00b 53.94s +53.78s ⚠️
dist/media-viewer.32e1b94c.js 4.51kb +0.00b 45.06s +44.90s ⚠️
dist/media-viewer.d9a8d8e5.js 3.98kb +0.00b 45.06s +44.90s ⚠️
dist/EmojiPickerComponent.0659235c.js 3.72kb +0.00b 53.94s +53.80s ⚠️
dist/png-chunks-extract.1bcf0dfb.js 3.58kb +0.00b 26.65s +26.49s ⚠️
dist/index.4fba8820.css 3.46kb +0.00b 54.74s +54.56s ⚠️
dist/dropzone.e14c32d9.js 3.29kb +0.00b 54.04s +53.87s ⚠️
dist/Modal.7ade13df.js 3.15kb +0.00b 26.91s +26.75s ⚠️
dist/clipboard.d13fb601.js 2.93kb +0.00b 54.04s +53.87s ⚠️
dist/16.01abc4bb.js 2.36kb +0.00b 26.91s +26.80s ⚠️
dist/ResourcedEmojiComponent.a1d3f4a0.js 2.12kb +0.00b 53.94s +53.80s ⚠️
dist/card.d1f2beda.js 2.06kb +0.00b 45.06s +44.90s ⚠️
dist/date.71db3fe8.js 1.86kb +0.00b 27.21s +27.10s ⚠️
dist/images.d62b15bd.js 1.80kb +0.00b 27.21s +27.10s ⚠️
dist/feedback.9958bdd4.js 1.77kb +0.00b 45.00s +44.87s ⚠️
dist/16.a4c09c54.js 1.75kb +0.00b 26.65s +26.49s ⚠️
dist/browser.7f2c1dda.js 1.69kb +0.00b 54.04s +53.87s ⚠️
dist/16.00df3a96.js 1.68kb +0.00b 26.65s +26.49s ⚠️
dist/workerHasher.c8ca1949.js 1.63kb +0.00b 53.94s +53.81s ⚠️
dist/workerHasher.c6d63a8c.js 1.63kb +0.00b 54.55s +54.38s ⚠️
dist/list-number.1094e49b.js 1.59kb +0.00b 27.21s +27.09s ⚠️
dist/status.01513cd7.js 1.59kb +0.00b 27.21s +27.09s ⚠️
dist/code.41dec3bc.js 1.51kb +0.00b 27.21s +27.10s ⚠️
dist/heading6.43c4a239.js 1.51kb +0.00b 44.46s +44.33s ⚠️
dist/heading3.86883cea.js 1.49kb +0.00b 44.46s +44.33s ⚠️
dist/link.cf6cf606.js 1.43kb +0.00b 27.21s +27.10s ⚠️
dist/16.fc05fc66.js 1.40kb +0.00b 26.65s +26.49s ⚠️
dist/heading5.eead537b.js 1.38kb +0.00b 44.46s +44.33s ⚠️
dist/emoji.209246d3.js 1.36kb +0.00b 27.21s +27.10s ⚠️
dist/16.c6b45ca4.js 1.35kb +0.00b 26.65s +26.49s ⚠️
dist/16.23ccd83c.js 1.35kb +0.00b 26.65s +26.49s ⚠️
dist/16.06271460.js 1.33kb +0.00b 26.99s +26.83s ⚠️
dist/16.04665c7c.js 1.33kb +0.00b 26.65s +26.48s ⚠️
dist/heading2.45d46a2f.js 1.32kb +0.00b 44.46s +44.33s ⚠️
dist/16.bc168422.js 1.29kb +0.00b 26.65s +26.49s ⚠️
dist/expand.44b4643e.js 1.29kb +0.00b 45.06s +44.93s ⚠️
dist/heading4.cc81126f.js 1.27kb +0.00b 44.46s +44.33s ⚠️
dist/16.c4b9ffab.js 1.25kb +0.00b 26.65s +26.49s ⚠️
dist/16.a9c08a24.js 1.22kb +0.00b 26.65s +26.53s ⚠️
dist/16.3be2d210.js 1.21kb +0.00b 26.65s +26.49s ⚠️
dist/16.c4ae24c0.js 1.20kb +0.00b 26.99s +26.88s ⚠️
dist/mention.bf94f359.js 1.20kb +0.00b 27.21s +27.09s ⚠️
dist/layout.2ab7fe1e.js 1.18kb +0.00b 27.21s +27.10s ⚠️
dist/Modal.41dab93a.js 1.17kb +0.00b 26.65s +26.49s ⚠️
dist/16.d748ad30.js 1.16kb +0.00b 26.65s +26.49s ⚠️
dist/heading1.e46ebd87.js 1.16kb +0.00b 44.46s +44.33s ⚠️
dist/16.dfa6b620.js 1.16kb +0.00b 26.65s +26.48s ⚠️
dist/divider.4e444466.js 1.16kb +0.00b 27.21s +27.10s ⚠️
dist/quote.f1661da4.js 1.15kb +0.00b 27.21s +27.09s ⚠️
dist/16.d91bdfc5.js 1.15kb +0.00b 26.65s +26.49s ⚠️
dist/16.76b33c8c.js 1.15kb +0.00b 26.65s +26.49s ⚠️
dist/16.2104d9ba.js 1.15kb +0.00b 26.65s +26.49s ⚠️
dist/16.5247c925.js 1.15kb +0.00b 26.65s +26.49s ⚠️
dist/action.5318380d.js 1.13kb +0.00b 27.21s +27.10s ⚠️
dist/component.c218dc1f.js 1.12kb +0.00b 26.91s +26.80s ⚠️
dist/media-card-analytics-error-boundary.e1f2c03b.js 1.12kb +0.00b 53.94s +53.78s ⚠️
dist/decision.12c8af60.js 1.12kb +0.00b 27.21s +27.10s ⚠️
dist/panel-warning.bda6bdb5.js 1.11kb +0.00b 27.21s +27.09s ⚠️
dist/16.9ad179a5.js 1.11kb +0.00b 26.65s +26.53s ⚠️
dist/list.f96161ec.js 1.08kb +0.00b 27.21s +27.09s ⚠️
dist/16.d102dfb8.js 1.07kb +0.00b 26.65s +26.49s ⚠️
dist/panel-error.02cac363.js 1.01kb +0.00b 27.21s +27.09s ⚠️
dist/panel.ba611692.js 1.01kb +0.00b 27.21s +27.09s ⚠️
dist/table.84de9360.js 1022.00b +0.00b 27.21s +27.09s ⚠️
dist/panel-success.c5920078.js 978.00b +0.00b 27.21s +27.09s ⚠️
dist/panel-note.671a06d0.js 974.00b +0.00b 27.21s +27.09s ⚠️
dist/media-viewer-analytics-error-boundary.b7edd41f.js 964.00b +0.00b 53.94s +53.78s ⚠️
dist/media-picker-analytics-error-boundary.f598f6fd.js 964.00b +0.00b 54.04s +53.87s ⚠️
dist/media-card-analytics-error-boundary.ca13875d.js 960.00b +0.00b 53.94s +53.78s ⚠️
dist/media-card-analytics-error-boundary.fb2a1470.js 960.00b +0.00b 54.15s +53.97s ⚠️
dist/simpleHasher.db850807.js 641.00b +0.00b 53.94s +53.80s ⚠️
dist/simpleHasher.660236a4.js 641.00b +0.00b 54.55s +54.38s ⚠️
dist/index.html 119.00b +0.00b 53.95s +53.87s ⚠️

Three.js ✅

Timings

Description Time Difference
Cold 7.02s +40.00ms
Cached 392.00ms -174.00ms 🚀

Cold Bundles

No bundle changes detected.

Cached Bundles

Bundle Size Difference Time Difference
dist/Three.js 579.69kb +0.00b 5.21s +5.14s ⚠️

Click here to view a detailed benchmark overview.

Base automatically changed from xxhash to v2 June 3, 2021 23:55
# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	packages/core/core/src/BundleGraph.js
#	packages/core/core/src/PackagerRunner.js
#	packages/core/core/src/RequestTracker.js
#	packages/core/core/src/Transformation.js
#	packages/core/core/src/requests/ConfigRequest.js
#	packages/packagers/js/src/index.js
#	packages/transformers/postcss/src/PostCSSTransformer.js
#	packages/utils/hash/index.js
#	packages/utils/hash/index.js.flow
#	packages/utils/hash/package.json
Comment on lines 68 to 69
// TODO: should we be mutating this here?
requestedAssetIds.clear();
Copy link
Member

Choose a reason for hiding this comment

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

Maybe leave this part in Parcel.js and do it after the build request finished?

optionsRef,
});

// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381

@devongovett devongovett merged commit 1ba0bd1 into v2 Jun 10, 2021
@devongovett devongovett deleted the packager-request branch June 10, 2021 04:24
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.

[parcel 2] does not minify css imported with bundle-text:
5 participants