perf(oxfmt): Use worker_threads by tinypool for prettier formatting#16618
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
106ee0d to
602ccaf
Compare
9938678 to
67808c2
Compare
worker_threads by tinypool for prettier formatting
243ce15 to
9737454
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors oxfmt to use worker threads for Prettier formatting via the tinypool library, enabling parallel execution on the JavaScript side to match the Rust side's multi-threaded architecture. Previously, while Rust operated in a multithreaded manner, the JS side remained single-threaded, causing sequential execution bottlenecks.
Key Changes:
- Adds
tinypooldependency for worker thread pool management - Updates
setupConfigcallback to acceptnumThreadsparameter matching Rayon's thread count - Splits Prettier logic into worker (
prettier-worker.ts) and proxy (prettier-proxy.ts) files
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
pnpm-lock.yaml |
Adds tinypool 2.0.0 to lockfile for both app and npm package |
npm/oxfmt/package.json |
Declares tinypool as production dependency |
apps/oxfmt/tsdown.config.ts |
Adds worker entry point and documents why tinypool cannot be bundled |
apps/oxfmt/src/main_napi.rs |
Updates TypeScript type annotation for setupConfigCb to include numThreads parameter |
apps/oxfmt/src/core/external_formatter.rs |
Updates callback signatures to pass num_threads to JavaScript side |
apps/oxfmt/src/cli/format.rs |
Passes thread count to external formatter setup before creating SourceFormatter |
apps/oxfmt/src-js/prettier-worker.ts |
New worker implementation that receives config via workerData and formats code in parallel |
apps/oxfmt/src-js/prettier-proxy.ts |
Refactored to create worker pool and dispatch formatting tasks to workers |
apps/oxfmt/src-js/bindings.d.ts |
Updates TypeScript signature for format function to reflect numThreads parameter |
apps/oxfmt/package.json |
Adds tinypool dependency for development builds |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
worker_threads by tinypool for prettier formattingworker_threads by tinypool for prettier formatting
9737454 to
c5885c5
Compare
Dunqing
left a comment
There was a problem hiding this comment.
Overall, it looks good! Just one thing that I do not know if it will work. Feel free to do it in the follow-up PR if you want.
c5885c5 to
c9770b9
Compare
Merge activity
|
…ng (#16618) Part of #16606 - Use `worker_threads` via `tinypool` lib - Until now, the Rust side had been operating entirely in a multithreaded manner, while the JS side remained single-threaded, resulting in sequential execution and waiting - Number of threads are the same value for Rust side - Also can be applied to embedded formatting path - Since `tinypool` couldn't be bundled, defined as `dependencies` in the `npm/oxfmt/package.json`
c9770b9 to
6f3aaba
Compare
…ng (#16618) Part of #16606 - Use `worker_threads` via `tinypool` lib - Until now, the Rust side had been operating entirely in a multithreaded manner, while the JS side remained single-threaded, resulting in sequential execution and waiting - Number of threads are the same value for Rust side - Also can be applied to embedded formatting path - Since `tinypool` couldn't be bundled, defined as `dependencies` in the `npm/oxfmt/package.json`
…ng (oxc-project#16618) Part of oxc-project#16606 - Use `worker_threads` via `tinypool` lib - Until now, the Rust side had been operating entirely in a multithreaded manner, while the JS side remained single-threaded, resulting in sequential execution and waiting - Number of threads are the same value for Rust side - Also can be applied to embedded formatting path - Since `tinypool` couldn't be bundled, defined as `dependencies` in the `npm/oxfmt/package.json`

Part of #16606
worker_threadsviatinypoollibtinypoolcouldn't be bundled, defined asdependenciesin thenpm/oxfmt/package.json