Skip to content

feat: run on webpack's shared threads via compiler.worker() - #769

Merged
alexander-akait merged 8 commits into
mainfrom
feat/compiler-worker
Nov 26, 2026
Merged

alexander-akait merged 8 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(), experiments.threads and the numWorkers option).

Today the plugin starts a jest-worker pool per compilation and ends it afterwards. webpack now owns one thread pool per process, shared with loader threads and other compilers and kept alive across watch rebuilds. On a webpack that has compiler.worker(), the plugin 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"), {
  numWorkers, // from `parallel`; ignored when `experiments.threads` configures the pool
});
await worker.run("minify", options); // or "transform"
  • experiments.threads off: numWorkers asks webpack for up to that many threads (capped at cores − 1), so minification stays parallel, on webpack's threads instead of jest-worker.
  • experiments.threads on: the configured pool applies.
  • jest-worker stays only for webpack without compiler.worker() and for minimizers that need child processes (supportsWorkerThreads() === false: swcMinify, esbuildMinify, minifyHtmlNode, swcMinifyHtml, swcMinifyHtmlFragment).

Measured locally with experiments.threads off (150 assets, terser, 4 cores → 3 threads, webpack from #23374, fresh process per run, median):

jest-worker compiler.worker
Production build (n=10): time / CPU 10.3 s / 36.8 s 10.0 s / 35.8 s
Production build: peak RSS 700 MB 749 MB (within run spread)
Watch, 5 builds (n=5): time / CPU 49.5 s / 172 s 39.6 s / 127 s
Watch, 5 builds: peak RSS 888 MB 1,140 MB

Watch trades memory for CPU: reused threads keep warm heaps instead of respawning each build.

What kind of change does this PR introduce?

feat

Did you add tests for your changes?

Yes: test/compiler-worker.test.js. The stubbed tests run on any webpack and cover numWorkers, the inline-function transform path and both jest-worker fallbacks; the real compiler.worker tests (threads on and off) skip until a webpack release ships it, and pass against webpack linked from #23374. The parallel suites hide compiler.worker() so they keep covering the jest-worker path.

Does this PR introduce a breaking change?

No. On webpack without compiler.worker() the plugin behaves as before.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

README parallel section updated.

Use of AI

Yes. Claude Code wrote the change, the tests and the benchmark, which were reviewed and run locally.


🤖 Generated with Claude Code

https://claude.ai/code/session_013FhutPfFxa3dMMtdTmt63i

Summary by CodeRabbit

  • New Features
    • Minimization now uses webpack’s shared worker threads when available, while retaining the existing worker-based fallback for older webpack versions.
    • Updated the parallel option documentation to explain how worker counts are controlled with webpack threads.

@changeset-bot

changeset-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c03dbab

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.51%. Comparing base (59e1a1c) to head (c03dbab).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #769      +/-   ##
==========================================
+ Coverage   98.50%   98.51%   +0.01%     
==========================================
  Files           6        6              
  Lines        1668     1684      +16     
  Branches      660      660              
==========================================
+ Hits         1643     1659      +16     
  Misses         24       24              
  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 →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The plugin uses webpack’s worker pool when compiler.worker() is available and worker threads are supported. Otherwise, it uses jest-worker. Cleanup ends only the tracked Jest worker. New tests cover worker selection, output, and pool reuse. The type definitions describe the shared worker API, and a Changeset declares a minor release.

Merge Risk: Low · previous review bd816

When webpack provides compiler.worker(), minification now runs on webpack's worker threads, and older webpack versions keep using jest-worker. The remaining open question is whether builds without experiments.threads still minify in parallel on the new path. That depends on upstream webpack behavior this review could not inspect. If webpack runs that path inline, those builds would lose parallelism but would still produce correct output.

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 "feat: run on webpack's shared threads via compiler.worker()" names the main change. The PR adds support for webpack's compiler.worker() so minimizers run on webpack's shared thread pool ins…
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 "feat: run on webpack's shared threads via compiler.worker()" names the main change. The PR adds support for webpack's compiler.worker() so minimizers run on webpack's shared thread pool instead of jest-worker when the API exists. The title is specific, concise, and matches the changeset, including the changeset note, the index.js worker selection, the types, the README, and the tests.

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

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: 5e0417dc-1c6d-4574-b9e1-87800afbf75e
Commits

Reviewing files that changed from the base of the PR and between 3538ff6 and bd81615.

Files selected for processing: 4

  • .changeset/compiler-worker-threads.md
  • README.md
  • src/index.js
  • test/compiler-worker.test.js
Files skipped from review as they are similar to previous changes: 2

  • .changeset/compiler-worker-threads.md
  • README.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 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
@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@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: 1

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: d012616e-38b0-475f-8023-5bcac894eea2
Commits

Reviewing files that changed from the base of the PR and between a3bfeb2 and b60fac7.

Files selected for processing: 9

  • .changeset/compiler-worker-threads.md
  • README.md
  • src/index.js
  • test/compiler-worker.test.js
  • test/helpers/hideCompilerWorker.js
  • test/helpers/index.js
  • test/parallel-option.test.js
  • test/parallel-stage.test.js
  • types/index.d.ts
Files skipped from review as they are similar to previous changes: 1

  • .changeset/compiler-worker-threads.md

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
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.
Pass `numWorkers` to `compiler.worker()`, so the plugin runs on webpack's
shared thread pool even without `experiments.threads`, replacing jest-worker
there. jest-worker stays for webpack without `compiler.worker()` and for
minimizers that need child processes.

Claude-Session: https://claude.ai/code/session_013FhutPfFxa3dMMtdTmt63i
@alexander-akait alexander-akait changed the title feat: use compiler.worker() when experiments.threads is enabled feat: run on webpack's shared threads via compiler.worker() Nov 22, 2026
Minimizers that report supportsWorkerThreads() === false run on webpack's
threads too. Without experiments.threads those threads are new for each
build, as jest-worker's were; with it they are shared. jest-worker stays
only for webpack without compiler.worker().

Claude-Session: https://claude.ai/code/session_013FhutPfFxa3dMMtdTmt63i
Both paths answer minify, transform and end; end() ends a jest-worker pool
and leaves webpack's threads to webpack.

Claude-Session: https://claude.ai/code/session_013FhutPfFxa3dMMtdTmt63i
@alexander-akait
alexander-akait merged commit c51265a into main Nov 26, 2026
31 checks passed
@alexander-akait
alexander-akait deleted the feat/compiler-worker branch November 26, 2026 15:58
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