Skip to content

feat(babel): add parallel option to transform in worker threads - #139

Open
NullVoxPopuli-ai-agent wants to merge 2 commits into
rolldown:mainfrom
NullVoxPopuli-ai-agent:babel-parallel
Open

NullVoxPopuli-ai-agent wants to merge 2 commits into
rolldown:mainfrom
NullVoxPopuli-ai-agent:babel-parallel

Conversation

@NullVoxPopuli-ai-agent

Copy link
Copy Markdown

Note

I am an AI bot: Claude Code, with the Claude Opus 5.5 model. @NullVoxPopuli asked me to open this PR. @NullVoxPopuli, please review.

Adds a parallel option to @rolldown/plugin-babel. With it, the plugin runs Babel in worker threads. This is a port of the same option from @rollup/plugin-babel (rollup/plugins#1956).

babel({
  parallel: true, // or a worker count
  plugins: [['@babel/plugin-proposal-decorators', { version: '2023-11' }]],
})

Behavior

  • true starts one worker per CPU core, with a maximum of 4. A number sets the worker count.
  • The pool starts on the first transform. It stops in closeBundle (not in watch mode) or closeWatcher.
  • Babel options must be structured-cloneable. If a plugin or preset is a function or an object, the plugin throws at startup and names the option, for example overrides[0].presets[0].
  • The rolldown part of a Rolldown Babel preset stays in the main thread. So its filters and hooks can still be functions.
  • Babel errors from a worker keep loc, so Rolldown still reports foo.js:1:13. workerpool drops nested error fields, so the worker adds a toJSON.

The other recent performance change in @rollup/plugin-babel (rollup/plugins#1954, hook filters) already exists in this plugin.

Benchmark

600 files with decorators, built from dist/, on an 8-core machine. Two rounds each, with the order mirrored:

parallel build time
off 83 to 86 s
2 43 to 46 s
4 26 to 28 s
8 21 s

Notes for review

  • New runtime dependency: workerpool@^10.0.3, the same package that the rollup plugin uses.
  • Errors from loadOptionsAsync now also get the [BabelError] prefix, because they are now inside the same try block as the transform.
  • The test build() helper now calls bundle.close(), so that worker pools stop.
  • Not tested: the Vite dev server. The Rolldown builds and the existing Vite build tests pass.

🤖 Generated with Claude Code

Port of the `parallel` option from @rollup/plugin-babel (rollup/plugins#1956).

Files go to a `workerpool` thread pool. Default worker count is the CPU
count, with a maximum of 4. The pool starts on the first transform and
stops in `closeBundle` (not in watch mode) or `closeWatcher`.

Babel options must be structured-cloneable, so the plugin rejects
function or object plugins and presets at startup. Rolldown preset
filters and hooks stay in the main thread, so they can be functions.

The other upstream performance change (rollup/plugins#1954, hook
filters) already exists in this plugin.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@socket-security

socket-security Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedworkerpool@​10.0.39710010090100

View full report

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

seems good to me

@NullVoxPopuli-ai-agent
NullVoxPopuli-ai-agent marked this pull request as ready for review September 25, 2026 17:29
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

idk if there is a better way to do this, but the purpose of doing this much work to see if a config is serializable is to provide a better error to consumers when part of their config is not serializable

@hyfdev
hyfdev requested a review from sapphi-red September 29, 2026 05:57

This branch has not been deployed

No deployments
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.

2 participants