Repository navigation
feat(babel): add parallel option to transform in worker threads - #139
NullVoxPopuli-ai-agent wants to merge 4 commits into
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
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
|
Would you add Also would you compare the performance with the following packages?
If the performance is same, I'd prefer the one on the bottom in the list as it has smaller package size. |
| const preset = presets[i] | ||
| // The `rolldown` part of a preset (filters and hooks) is only used in the main thread. | ||
| const babelPreset = typeof preset === 'object' && 'rolldown' in preset ? preset.preset : preset | ||
| if (!isCloneable(babelPreset)) return `${path}[${i}]` |
There was a problem hiding this comment.
Could we use structuredClone? It has the overhead of actually cloning the vaules, but I think that can be solved by running the check after sending the message was errored.
There was a problem hiding this comment.
Done in d7fb6dc. isCloneable is now a structuredClone call in a try block.
The check runs only after a worker message fails with a DataCloneError. The error then names the option, for example "overrides[0].presets[0]" cannot be sent to a worker thread.
(AI reply: Claude Code for @NullVoxPopuli)
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>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…Clone` for the option check Review follow-up. `workerpool`, `tinypool`, and `artichokie` give the same build time in the benchmark, so the plugin uses `artichokie`, the smallest package. The check for options that cannot go to a worker now uses `structuredClone`. It runs only after a worker message fails with a `DataCloneError`, so builds with valid options do not pay for the clone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compares `parallel: false` and `parallel: true` on 100 generated modules with decorators. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b06cc6f to
3eff276
Compare
|
Both are done.
Pool comparison, 4 workers, mean build time of 12 rounds with a rotated order:
The pools are equal inside the noise (standard deviation 0.01 to 0.08 s), so the plugin now uses Two notes on
(AI reply: Claude Code for @NullVoxPopuli) |
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
paralleloption 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).Behavior
truestarts one worker per CPU core, with a maximum of 4. A number sets the worker count.closeBundle(not in watch mode) orcloseWatcher.overrides[0].presets[0].rolldownpart of a Rolldown Babel preset stays in the main thread. So its filters and hooks can still be functions.loc, so Rolldown still reportsfoo.js:1:13. The structured clone of an error dropsloc, so the worker sends the error as a plain object.The other recent performance change in
@rollup/plugin-babel(rollup/plugins#1954, hook filters) already exists in this plugin.Benchmark
packages/babel/benchmarkcomparesparallel: falseandparallel: trueon 100 generated modules with decorators. Runpnpm bench --reporter=verbosein that directory. On an 8-core machine, with 10 samples:parallelfalsetrue(4 workers)Pool packages
Build time with each pool package, 4 workers, 12 rounds with a rotated order:
parallel: false)workerpooltinypoolartichokieThe differences between the pools are inside the noise (standard deviation 0.01 to 0.08 s), so the plugin uses
artichokie, the smallest package.Notes for review
artichokie@^0.4.5.artichokiestop()callsunref()on the workers and does not terminate them. A process that runs many builds keeps the idle workers until it exits.loadOptionsAsyncnow also get the[BabelError]prefix, because they are now inside the sametryblock as the transform.build()helper now callsbundle.close(), so that worker pools stop.🤖 Generated with Claude Code