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

Parcel plugin dev dep cache invalidation and hot reloading #5802

Merged
merged 21 commits into from Mar 1, 2021

Conversation

devongovett
Copy link
Member

@devongovett devongovett commented Feb 8, 2021

T-377 T-383

This tracks dev dependencies (e.g. parcel plugins) in the request graph so that we invalidate when they are updated. There are dev_dep_request nodes in the graph which are connected to all of the files that the plugins include via require (tracked by the NodePackageManager). They also store a hash of all of these files. When a file changes, it invalidates the dev_dep_request, which in turns invalidates the asset_request. When the asset request is re-run, all of the valid dev_dep_requests are sent to the worker with their hash. This way we avoid recomputing the hash on each run, except if the dev dep is invalid.

Screen Shot 2021-02-08 at 10 17 39 AM

The dev_dep_request nodes are shared between multiple asset_requests. This reduces the number of edges in the graph because only one edge is needed from asset_request to dev_dep_request rather than an edge to each individual file. It is possible, however, for multiple dev_dep_requests for the same plugin to exist, for example, due to conditional requires. A plugin may require different dependencies depending on the asset (e.g. parcel uses lazy requires that only load a module once it is used). The dependencies are recomputed for each request (though individual file hashes are cached during builds), and a new node will be created for each unique hash.

Aside from enabling cache invalidation for plugins (supporting manual editing of node_modules for debugging, patch-package, local plugins, etc.), this also enables HMR for parcel plugins and their dependencies. Since we already watch all dependencies and trigger a rebuild, we just need to clear the node require cache for that plugin and pretty much get HMR for free. This lets you work on a Parcel plugin or other dev dependency and see the results immediately without restarting the process. 😄

Parcel.Plugin.HMR.mov

@height
Copy link

height bot commented Feb 8, 2021

This pull request has been linked to 2 tasks:

💡Tip: Add "Close T-383" to the pull request title or description, to a commit message, or in a comment to mark this task as "Done" when the pull request is merged.

@parcel-benchmark
Copy link

parcel-benchmark commented Feb 8, 2021

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 3.57s +43.00ms
Cached 514.00ms +46.00ms ⚠️

Cold Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.d5807e82.webp 102.94kb +0.00b 140.00ms +32.00ms ⚠️
dist/modern/parcel.d5807e82.webp 102.94kb +0.00b 101.00ms +25.00ms ⚠️
dist/legacy/index.76ce4b0c.js 1.12kb +0.00b 1.20s +502.00ms ⚠️
dist/modern/index.b43fcc94.js 1.12kb +0.00b 711.00ms +102.00ms ⚠️
dist/modern/index.html 701.00b +0.00b 686.00ms +101.00ms ⚠️
dist/legacy/index.44edca46.css 77.00b +0.00b 1.20s +72.00ms ⚠️
dist/modern/index.0bc656bc.css 77.00b +0.00b 1.20s +163.00ms ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.d5807e82.webp 102.94kb +0.00b 91.00ms +24.00ms ⚠️

React HackerNews ✅

Timings

Description Time Difference
Cold 21.64s -442.00ms
Cached 1.23s +113.00ms ⚠️

Cold Bundles

Bundle Size Difference Time Difference
dist/PermalinkedComment.0a19c7e4.js 4.24kb +0.00b 995.00ms -450.00ms 🚀
dist/UserProfile.b2960402.js 1.78kb +0.00b 995.00ms -450.00ms 🚀
dist/NotFound.f3269ae7.js 542.00b +0.00b 261.00ms -293.00ms 🚀
dist/logo.24c8bf9e.png 274.00b +0.00b 68.00ms -125.00ms 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/NotFound.f3269ae7.js 542.00b +0.00b 105.00ms -31.00ms 🚀
dist/logo.24c8bf9e.png 274.00b +0.00b 112.00ms +8.00ms ⚠️

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 2.57m +2.83s
Cached 3.58s +260.00ms ⚠️

Cold Bundles

Bundle Size Difference Time Difference
dist/index.68c5e99f.js 2.46mb -8.00b 🚀 1.49m +17.69s ⚠️
dist/pdfRenderer.f5a3f4a7.js 1.11mb -3.00b 🚀 1.49m +42.35s ⚠️
dist/editorView.07b73572.js 588.08kb +0.00b 35.82s -50.87s 🚀
dist/popup.119ff481.js 171.12kb +0.00b 20.13s +3.09s ⚠️
dist/EmojiPickerComponent.6d8f513a.js 139.84kb +0.00b 13.29s -806.00ms 🚀
dist/Toolbar.56c4be53.js 100.68kb +0.00b 18.93s -1.75s 🚀
dist/media-viewer.ebcb5e1e.js 73.43kb +0.00b 13.78s +2.46s ⚠️
dist/card.df70c9b7.js 54.67kb +0.00b 11.55s -2.62s 🚀
dist/esm.e3419f0a.js 27.83kb +0.00b 11.56s +2.67s ⚠️
dist/DatePicker.faca45d0.js 21.38kb +0.00b 11.27s +4.39s ⚠️
dist/dropzone.3ae9a030.js 16.15kb +0.00b 14.93s -2.08s 🚀
dist/ui.15dd7acd.js 14.30kb +0.00b 11.38s -2.71s 🚀
dist/component.677fad45.js 6.23kb +0.00b 4.65s +629.00ms ⚠️
dist/card.3a4028bd.js 5.74kb +0.00b 13.37s +2.15s ⚠️
dist/media-viewer.f15e56f4.js 4.01kb +0.00b 13.18s +1.61s ⚠️
dist/EmojiPickerComponent.4991ddd4.js 3.68kb +0.00b 9.88s +994.00ms ⚠️
dist/dropzone.d1e8004d.js 3.46kb +0.00b 19.01s +2.02s ⚠️
dist/index.ece3a13e.css 3.46kb +0.00b 20.08s -51.34s 🚀
dist/Modal.08282ab6.js 3.23kb +0.00b 4.42s +846.00ms ⚠️
dist/clipboard.6a6e5fbd.js 3.00kb +0.00b 14.93s -962.00ms 🚀
dist/ResourcedEmojiComponent.5046c0ff.js 2.19kb +0.00b 11.36s -2.73s 🚀
dist/card.2888338b.js 2.15kb +0.00b 13.82s +2.24s ⚠️
dist/feedback.facaac2e.js 1.87kb +0.00b 11.25s +4.39s ⚠️
dist/16.a9ea9b41.js 1.86kb +0.00b 5.47s -621.00ms 🚀
dist/browser.8883c452.js 1.85kb +0.00b 19.11s +3.21s ⚠️
dist/16.89d45d15.js 1.80kb +0.00b 4.98s +671.00ms ⚠️
dist/workerHasher.d607e0b8.js 1.77kb +0.00b 15.35s -1.57s 🚀
dist/list-number.d4568b49.js 1.69kb +0.00b 7.34s +1.56s ⚠️
dist/link.5be155be.js 1.54kb +0.00b 7.34s +1.59s ⚠️
dist/heading6.5a6082c8.js 1.53kb +0.00b 6.46s -398.00ms 🚀
dist/heading3.1c92891c.js 1.52kb +0.00b 6.40s -2.07s 🚀
dist/16.07ccad90.js 1.51kb +0.00b 5.65s +406.00ms ⚠️
dist/16.00f25203.js 1.47kb +0.00b 4.98s +671.00ms ⚠️
dist/16.02056ae6.js 1.47kb +0.00b 5.65s +407.00ms ⚠️
dist/heading5.88bc6249.js 1.41kb +0.00b 6.41s -456.00ms 🚀
dist/expand.4a483eb0.js 1.39kb +0.00b 11.25s +4.39s ⚠️
dist/16.fa5f411c.js 1.36kb +0.00b 5.47s -621.00ms 🚀
dist/heading2.22de70fe.js 1.34kb +0.00b 6.40s -2.07s 🚀
dist/16.d10db5a3.js 1.32kb +0.00b 6.00s +609.00ms ⚠️
dist/heading4.a2524c70.js 1.29kb +0.00b 6.41s -2.06s 🚀
dist/layout.81f2196c.js 1.28kb +0.00b 7.34s +1.59s ⚠️
dist/16.acff901d.js 1.27kb +0.00b 5.47s -621.00ms 🚀
dist/component.233c7a65.js 1.26kb +0.00b 4.42s +845.00ms ⚠️
dist/16.015dfb9d.js 1.26kb +0.00b 5.28s +474.00ms ⚠️
dist/16.828b958e.js 1.26kb +0.00b 5.65s +406.00ms ⚠️
dist/16.ec84a250.js 1.26kb +0.00b 4.98s +671.00ms ⚠️
dist/media-card-analytics-error-boundary.ff0177b3.js 1.25kb +0.00b 13.37s +2.37s ⚠️
dist/16.458399e0.js 1.23kb +0.00b 4.42s +845.00ms ⚠️
dist/list.2dfe3f18.js 1.19kb +0.00b 5.92s -705.00ms 🚀
dist/heading1.cc82b077.js 1.19kb +0.00b 8.43s +2.27s ⚠️
dist/media-picker-analytics-error-boundary.49b32f4d.js 1023.00b +0.00b 13.91s -3.08s 🚀
dist/media-card-analytics-error-boundary.9a500f44.js 1019.00b +0.00b 11.59s +592.00ms ⚠️
dist/media-viewer-analytics-error-boundary.83da5db2.js 1015.00b +0.00b 13.53s +1.96s ⚠️
dist/index.html 119.00b +0.00b 3.14s +724.00ms ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/pdfRenderer.f5a3f4a7.js 1.11mb -4.00b 🚀 740.00ms +47.00ms ⚠️
dist/popup.9244297f.js 171.12kb +0.00b 740.00ms +38.00ms ⚠️
dist/EmojiPickerComponent.6d8f513a.js 139.84kb +0.00b 725.00ms +46.00ms ⚠️
dist/media-viewer.ebcb5e1e.js 73.43kb +0.00b 740.00ms +47.00ms ⚠️
dist/card.1d931b4c.js 52.43kb +0.00b 747.00ms +39.00ms ⚠️
dist/Modal.3920d345.js 39.59kb +0.00b 695.00ms +91.00ms ⚠️
dist/component.ad27194c.js 31.05kb +0.00b 695.00ms +39.00ms ⚠️
dist/esm.e3419f0a.js 27.83kb +0.00b 725.00ms +46.00ms ⚠️
dist/component.f25dcadb.js 22.80kb +0.00b 649.00ms +44.00ms ⚠️
dist/DatePicker.faca45d0.js 21.38kb +0.00b 725.00ms +60.00ms ⚠️
dist/js.8167e2d5.js 16.55kb +0.00b 639.00ms +35.00ms ⚠️
dist/dropzone.b7224a83.js 16.15kb +0.00b 747.00ms +41.00ms ⚠️
dist/workerHasher.bc6346e1.js 11.90kb +0.00b 725.00ms +46.00ms ⚠️
dist/card.3a4028bd.js 5.74kb +0.00b 740.00ms +47.00ms ⚠️
dist/media-viewer.f15e56f4.js 4.01kb +0.00b 740.00ms +47.00ms ⚠️
dist/png-chunks-extract.608f438d.js 3.56kb +0.00b 639.00ms +34.00ms ⚠️
dist/dropzone.d1e8004d.js 3.46kb +0.00b 740.00ms +38.00ms ⚠️
dist/clipboard.6a6e5fbd.js 3.00kb +0.00b 747.00ms +41.00ms ⚠️
dist/card.2888338b.js 2.15kb +0.00b 740.00ms +38.00ms ⚠️
dist/browser.8883c452.js 1.85kb +0.00b 747.00ms +39.00ms ⚠️
dist/workerHasher.31326e89.js 1.77kb +0.00b 725.00ms +46.00ms ⚠️
dist/16.02056ae6.js 1.47kb +0.00b 656.00ms +35.00ms ⚠️
dist/Modal.44e980e0.js 1.29kb +0.00b 639.00ms +35.00ms ⚠️
dist/16.015dfb9d.js 1.26kb +0.00b 656.00ms +35.00ms ⚠️
dist/media-card-analytics-error-boundary.ff0177b3.js 1.25kb +0.00b 740.00ms +48.00ms ⚠️
dist/16.458399e0.js 1.23kb +0.00b 695.00ms +38.00ms ⚠️
dist/media-picker-analytics-error-boundary.49b32f4d.js 1023.00b +0.00b 747.00ms +45.00ms ⚠️
dist/media-card-analytics-error-boundary.b884d580.js 1019.00b +0.00b 747.00ms +39.00ms ⚠️
dist/media-viewer-analytics-error-boundary.83da5db2.js 1015.00b +0.00b 740.00ms +39.00ms ⚠️

Three.js ✅

Timings

Description Time Difference
Cold 16.48s -220.00ms
Cached 615.00ms +35.00ms ⚠️

Cold Bundles

No bundle changes detected.

Cached Bundles

Bundle Size Difference Time Difference
dist/Three.js 580.60kb +0.00b 119.00ms +11.00ms ⚠️

Click here to view a detailed benchmark overview.

Base automatically changed from resolver-invalidation to v2 February 12, 2021 23:00
@devongovett devongovett marked this pull request as ready for review February 21, 2021 19:10
@devongovett devongovett changed the title WIP: Parcel plugin dev dep cache invalidation and hot reloading Parcel plugin dev dep cache invalidation and hot reloading Feb 21, 2021
@devongovett devongovett mentioned this pull request Feb 22, 2021
4 tasks
@wbinnssmith
Copy link
Contributor

This doesn't introduce any issues in our app, so I'm on board with merging it. Though it would probably benefit from a technical review from @padmaia 😅

config.shouldReload();
contents.__contains_functions = true;

// Also add the config as a dev dependency so we attempt to reload in watch mode.
Copy link
Member

@mischnic mischnic Feb 26, 2021

Choose a reason for hiding this comment

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

Couldn't config.getConfig do this for JS configs? loadConfig in utils does checks for endsWith(".js") anyway

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, will do in a follow up pr.

packages/transformers/babel/src/config.js Outdated Show resolved Hide resolved
packages/core/types/index.js Show resolved Hide resolved
packages/core/integration-tests/test/cache.js Outdated Show resolved Hide resolved
@devongovett devongovett merged commit 806cc65 into v2 Mar 1, 2021
@devongovett devongovett deleted the dev-dep-invalidation branch March 1, 2021 16:15
@wbinnssmith wbinnssmith restored the dev-dep-invalidation branch March 18, 2021 21:36
@wbinnssmith wbinnssmith deleted the dev-dep-invalidation branch March 18, 2021 21:38
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