Skip to content

feat: use compiler.worker() when experiments.threads is enabled - #769

Open
alexander-akait wants to merge 4 commits into
mainfrom
feat/compiler-worker
Open

alexander-akait wants to merge 4 commits into
mainfrom
feat/compiler-worker

Conversation

@alexander-akait

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

Copy link
Copy Markdown
Member

Summary

Depends on webpack/webpack#23374 (compiler.worker() and experiments.threads).

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.

const worker = compiler.worker(require.resolve("./minify"));
await worker.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.


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • When webpack’s thread experiments are enabled and supported, minimization can use webpack’s shared worker pool and reuse its threads across builds.
    • When threading is disabled or the shared pool is unavailable, minimization continues to use the existing worker behavior.
    • TypeScript definitions now include types for webpack’s compiler worker integration.

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

changeset-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a3bfeb2

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

This PR includes changesets to release 1 package
Name Type
minimizer-webpack-plugin Minor

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

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.33%. Comparing base (317e853) to head (a3bfeb2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #769      +/-   ##
==========================================
+ Coverage   98.32%   98.33%   +0.01%     
==========================================
  Files           6        6              
  Lines        1667     1679      +12     
  Branches      659      664       +5     
==========================================
+ Hits         1639     1651      +12     
  Misses         27       27              
  Partials        1        1              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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 Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 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.
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.

Share

Recent 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: 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.

@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

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

Comment thread src/index.js Resolved
Comment thread test/compiler-worker.test.js Resolved
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