Repository navigation
perf: share the compile cache with child processes and worker threads - #4872
Conversation
`enableCompileCache()` only covers the current thread, so minimizer workers and other child processes compiled every module from scratch. Setting `NODE_COMPILE_CACHE` to the cache directory hands it to them at startup, unless the environment already names one or disables the cache.
🦋 Changeset detectedLatest commit: 0b7bf17 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview is available (3af13e1). Install it locally:
npm i -D webpack-cli@https://pkg.pr.new/webpack-cli@3af13e1
yarn add -D webpack-cli@https://pkg.pr.new/webpack-cli@3af13e1
pnpm add -D webpack-cli@https://pkg.pr.new/webpack-cli@3af13e1 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4872 +/- ##
==========================================
- Coverage 94.86% 94.84% -0.02%
==========================================
Files 14 14
Lines 5626 5626
Branches 841 841
==========================================
- Hits 5337 5336 -1
- Misses 288 289 +1
Partials 1 1 see 1 file with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe CLI now stores the directory returned by Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
88f29942-d8b4-4f2e-aeb1-c108ee985686
📒 Files selected for processing: 5
.changeset/share-compile-cache-with-child-processes.mdpackages/webpack-cli/bin/cli.jstest/build/compile-cache/compile-cache.test.jstest/build/compile-cache/src/index.jstest/build/compile-cache/webpack.config.js
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
A cache a preload already enabled reports its version-tagged directory, which a child would tag again. Also exit the test config from the write callback so the report survives an asynchronous pipe.
Summary
enableCompileCache()only covers the CLI's own thread, so minimizer workers (terser, css/html minimizers) and any other child process or worker thread compiled every module from scratch. The CLI now setsNODE_COMPILE_CACHEto the cache directory, which Node reads at startup, unless the environment already names one or disables the cache. This is the same fix as webpack/webpack#22706 made inwebpack/bin/webpack.js; runningwebpack-clidirectly still missed it.What a config run by the CLI sees (Node 22.22):
/tmp/node-compile-cache/v22.22.0-…/tmp/node-compile-cache/v22.22.0-…undefined/tmp/node-compile-cache/v22.22.0-…undefined/tmp/node-compile-cache/v22.22.0-…Production build with 8 entries (terser runs in its workers), warm cache, median of 5 runs: 802 ms → 750 ms.
What kind of change does this PR introduce?
perf
Did you add tests for your changes?
Yes:
test/build/compile-cache/compile-cache.test.js. The config starts a child process and a worker thread and reports the cache directory each one sees. It covers handing the cache on, keeping a directory set in the environment, andNODE_DISABLE_COMPILE_CACHE. The first case fails without the fix. On Node 20 (no compile cache), it checks that nothing is handed on. I ran it on Node 22 and Node 20.Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a
Use of AI
Written with Claude Code: it compared the CLI with the webpack fix, reproduced the missing cache in child processes and worker threads, wrote the fix and the test, and measured the build. Directed and reviewed by the author.
🤖 Generated with Claude Code
https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo
Generated by Claude Code
Summary by CodeRabbit
NODE_COMPILE_CACHEvalue is preserved, and preload-enabled caching avoids adding another directory setting.NODE_DISABLE_COMPILE_CACHEis set.