Skip to content

perf: share the compile cache with child processes and worker threads - #4872

Merged
alexander-akait merged 2 commits into
mainfrom
bugfix/share-compile-cache-with-child-processes
Oct 16, 2026
Merged

alexander-akait merged 2 commits into
mainfrom
bugfix/share-compile-cache-with-child-processes

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

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 sets NODE_COMPILE_CACHE to 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 in webpack/bin/webpack.js; running webpack-cli directly still missed it.

// before
enableCompileCache();

// after
const { directory } = enableCompileCache();
if (directory && process.env.NODE_COMPILE_CACHE === undefined) {
  process.env.NODE_COMPILE_CACHE = directory;
}

What a config run by the CLI sees (Node 22.22):

Before After
CLI process /tmp/node-compile-cache/v22.22.0-… /tmp/node-compile-cache/v22.22.0-…
child process undefined /tmp/node-compile-cache/v22.22.0-…
worker thread 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, and NODE_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

  • New Features
    • Compile-cache settings are shared with child processes and worker threads, allowing them to reuse the same cache directory.
    • An explicitly configured NODE_COMPILE_CACHE value is preserved, and preload-enabled caching avoids adding another directory setting.
    • Compile caching remains disabled when NODE_DISABLE_COMPILE_CACHE is set.
    • When compile-cache support is unavailable, child processes and workers continue without a cache directory.

`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-bot

changeset-bot Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0b7bf17

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack-cli Patch

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

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview is available (3af13e1).

Install it locally:

  • npm
npm i -D webpack-cli@https://pkg.pr.new/webpack-cli@3af13e1
  • yarn
yarn add -D webpack-cli@https://pkg.pr.new/webpack-cli@3af13e1
  • pnpm
pnpm add -D webpack-cli@https://pkg.pr.new/webpack-cli@3af13e1

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.84%. Comparing base (5d4e9e4) to head (0b7bf17).

Additional details and impacted files

Impacted file tree graph

@@            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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5d4e9e4...0b7bf17. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 33746483-a7ba-43f5-a1d5-dc0f57a48fe2
📥 Commits

Reviewing files that changed from the base of the PR and between 54c7b04 and 0b7bf17.

📒 Files selected for processing: 4
  • packages/webpack-cli/bin/cli.js
  • test/build/compile-cache/compile-cache.test.js
  • test/build/compile-cache/preload.js
  • test/build/compile-cache/webpack.config.js
🚧 Files skipped from review as they are similar to previous changes: 1
  • test/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; 6 remain after this review.

Walkthrough

The CLI now stores the directory returned by enableCompileCache() and sets NODE_COMPILE_CACHE when compile caching is enabled and the variable is unset. New tests check compile-cache paths reported by the CLI, a child process, and a worker. They also check behavior when a cache directory is configured, compile-cache support is unavailable, or NODE_DISABLE_COMPILE_CACHE is set to "1".

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 0b7bf

The CLI and its child processes and workers use the same compile cache, including when a preload enabled it first. No actionable merge risk remains in the reviewed change.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: sharing the compile cache with child processes and worker threads.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 5…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 Biome (2.5.14)
packages/webpack-cli/bin/cli.js

File contains syntax errors that prevent linting: Line 32: Illegal return statement outside of a function

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

test/build/compile-cache/compile-cache.test.js

Oops! Something went wrong! :(

ESLint: 10.12.0

Error: Error while loading rule 'jest/no-deprecated-functions': Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly
Occurred while linting /test/build/compile-cache/compile-cache.test.js
at detectJestVersion (/.eslint-tmp/node_modules/eslint-plugin-jest/lib/rules/utils/detectJestVersion.js:22:9)
at create (/.eslint-tmp/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js:31:107)
at Object.create (/.eslint-tmp/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:39:20)
at createRuleListeners (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:502:15)
at /.eslint-tmp/node_modules/eslint/lib/linter/linter.js:628:7
at Array.forEach ()
at runRules (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:562:31)
at #flatVerifyWithoutProcessors (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:1297:4)
at Linter._verifyWithFlatConfigArrayAndWithoutProcessors (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:1382:43)
at Linter._verifyWithFlatConfigArray (/.eslint-tmp/node_modules/eslint/lib/linter/linter.js:1449:15)

test/build/compile-cache/preload.js

ESLint skipped: the matched ESLint configuration already failed (plugin-compatibility).

test/build/compile-cache/webpack.config.js

ESLint skipped: the matched ESLint configuration already failed (plugin-compatibility).

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 88f29942-d8b4-4f2e-aeb1-c108ee985686
📥 Commits

Reviewing files that changed from the base of the PR and between 5d4e9e4 and 54c7b04.

📒 Files selected for processing: 5
  • .changeset/share-compile-cache-with-child-processes.md
  • packages/webpack-cli/bin/cli.js
  • test/build/compile-cache/compile-cache.test.js
  • test/build/compile-cache/src/index.js
  • test/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.

Comment thread packages/webpack-cli/bin/cli.js Outdated
Comment thread test/build/compile-cache/webpack.config.js Outdated
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.
@alexander-akait
alexander-akait merged commit 3af13e1 into main Oct 16, 2026
40 of 41 checks passed
@alexander-akait
alexander-akait deleted the bugfix/share-compile-cache-with-child-processes branch October 16, 2026 08: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.

1 participant