You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: use compiler.worker() when experiments.threads is enabled - #769
Today the plugin starts a jest-worker pool per compilation and ends it afterwards. With experiments.threads, webpack owns one pool per compiler, shared with loader threads and kept alive across watch rebuilds. The plugin now uses it, lazily: compiler.worker() is called only when the first asset needs a worker, and the plugin never starts or ends threads.
constworker=compiler.worker(require.resolve("./minify"));awaitworker.run("minify",options);// or "transform"
jest-worker stays as the fallback: older webpack, experiments.threads off, and minimizers that need child processes (supportsWorkerThreads() === false).
Measured locally (12 assets of 250–300 KB, 4 cores, webpack from #23374, fresh process per run, identical output):
jest-worker
compiler.worker
Production build (n=7)
9.8 s
9.4 s (within spread)
Watch rebuild, memory cache (n=5 × 3)
1.46 s, 3.3 s CPU
0.94 s, 1.1 s CPU
Peak RSS, watch
816 MB
776 MB
What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes: test/compiler-worker.test.js. Two tests stub compiler.worker and run on any webpack; two use the real compiler.worker and skip until a webpack release ships it (they pass against webpack linked from #23374).
Does this PR introduce a breaking change?
No. Without experiments.threads the plugin behaves as before.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a until webpack documents experiments.threads.
Use of AI
Yes. Claude Code wrote the change, the tests and the benchmark, which were reviewed and run locally.
Webpack's shared pool lives as long as the compiler and is shared with loader threads, so the plugin no longer starts and ends its own jest-worker pool per compilation. jest-worker stays for older webpack, threads off, and minimizers that need child processes.
No actionable comments were generated in the recent review.
Walkthrough
The plugin uses webpack’s shared worker pool when compiler.worker() is available, experiments.threads is enabled, configured minimizers permit worker threads, and Node supports them. Otherwise, it uses jest-worker. Cleanup ends only the tracked Jest worker. New tests cover worker selection, output parity, and pool reuse. The type definitions describe the shared worker API, and a Changeset declares a minor release.
Merge Risk: Minimal · up to a3bfe
The change adds opt-in use of webpack's shared worker pool when experiments.threads is enabled. Behavior is unchanged otherwise, and jest-worker remains the fallback. No actionable merge-blocking risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title states the main change: when webpack's experiments.threads is enabled, the plugin uses compiler.worker() instead of jest-worker. The changeset, src/index.js, the new tests, and the types all…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title states the main change: when webpack's experiments.threads is enabled, the plugin uses compiler.worker() instead of jest-worker. The changeset, src/index.js, the new tests, and the types all implement this behavior, so the title matches the changeset. It uses the conventional feat: prefix and is specific enough for a teammate scanning history.
Finishing Touches
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.
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/compiler-worker.test.js
Oops! Something went wrong! :(
ESLint: 10.15.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/compiler-worker.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)
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 597b5192-96c6-4ea8-ab3b-bdda2c36d201
Commits
Reviewing files that changed from the base of the PR and between 5f5a769 and a3bfeb2.
Files selected for processing: 1
test/compiler-worker.test.js
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: de555875-d688-4afc-933d-c6b15f2950dd
Commits
Reviewing files that changed from the base of the PR and between 317e853 and 819fa22.
Files selected for processing: 4
.changeset/compiler-worker-threads.md
src/index.js
test/compiler-worker.test.js
types/index.d.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Depends on webpack/webpack#23374 (
compiler.worker()andexperiments.threads).Today the plugin starts a
jest-workerpool per compilation and ends it afterwards. Withexperiments.threads, webpack owns one pool per compiler, shared with loader threads and kept alive across watch rebuilds. The plugin now uses it, lazily:compiler.worker()is called only when the first asset needs a worker, and the plugin never starts or ends threads.jest-workerstays as the fallback: older webpack,experiments.threadsoff, and minimizers that need child processes (supportsWorkerThreads() === false).Measured locally (12 assets of 250–300 KB, 4 cores, webpack from #23374, fresh process per run, identical output):
What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes:
test/compiler-worker.test.js. Two tests stubcompiler.workerand run on any webpack; two use the realcompiler.workerand skip until a webpack release ships it (they pass against webpack linked from #23374).Does this PR introduce a breaking change?
No. Without
experiments.threadsthe plugin behaves as before.If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a until webpack documents
experiments.threads.Use of AI
Yes. Claude Code wrote the change, the tests and the benchmark, which were reviewed and run locally.
Generated by Claude Code
Summary by CodeRabbit