Skip to content

perf(oxfmt): Use worker_threads by tinypool for prettier formatting#16618

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-09-refactor_oxfmt_use_worker_threads_by_tinypool_for_formatfile_
Dec 9, 2025
Merged

perf(oxfmt): Use worker_threads by tinypool for prettier formatting#16618
graphite-app[bot] merged 1 commit intomainfrom
12-09-refactor_oxfmt_use_worker_threads_by_tinypool_for_formatfile_

Conversation

@leaysgur
Copy link
Copy Markdown
Member

@leaysgur leaysgur commented Dec 9, 2025

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

@github-actions github-actions bot added A-cli Area - CLI A-formatter Area - Formatter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Dec 9, 2025
Copy link
Copy Markdown
Member Author

leaysgur commented Dec 9, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@leaysgur leaysgur force-pushed the 12-09-refactor_oxfmt_use_worker_threads_by_tinypool_for_formatfile_ branch from 106ee0d to 602ccaf Compare December 9, 2025 01:12
@leaysgur leaysgur force-pushed the 12-09-refactor_oxfmt_use_worker_threads_by_tinypool_for_formatfile_ branch 7 times, most recently from 9938678 to 67808c2 Compare December 9, 2025 03:06
@leaysgur leaysgur changed the title refactor(oxfmt): Use worker_threads by tinypool for formatFile() refactor(oxfmt): Use worker_threads by tinypool for prettier formatting Dec 9, 2025
@leaysgur leaysgur force-pushed the 12-09-refactor_oxfmt_use_worker_threads_by_tinypool_for_formatfile_ branch 2 times, most recently from 243ce15 to 9737454 Compare December 9, 2025 03:32
@leaysgur leaysgur marked this pull request as ready for review December 9, 2025 03:38
Copilot AI review requested due to automatic review settings December 9, 2025 03:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 tinypool dependency for worker thread pool management
  • Updates setupConfig callback to accept numThreads parameter 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.

@Boshen Boshen changed the title refactor(oxfmt): Use worker_threads by tinypool for prettier formatting perf(oxfmt): Use worker_threads by tinypool for prettier formatting Dec 9, 2025
@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label Dec 9, 2025
@leaysgur leaysgur force-pushed the 12-09-refactor_oxfmt_use_worker_threads_by_tinypool_for_formatfile_ branch from 9737454 to c5885c5 Compare December 9, 2025 03:51
Copy link
Copy Markdown
Member

@Dunqing Dunqing left a comment

Choose a reason for hiding this comment

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

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.

@leaysgur leaysgur requested a review from Dunqing December 9, 2025 03:52
@leaysgur leaysgur force-pushed the 12-09-refactor_oxfmt_use_worker_threads_by_tinypool_for_formatfile_ branch from c5885c5 to c9770b9 Compare December 9, 2025 03:58
Copy link
Copy Markdown
Member

@Dunqing Dunqing left a comment

Choose a reason for hiding this comment

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

Great!

@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Dec 9, 2025
Copy link
Copy Markdown
Member

Dunqing commented Dec 9, 2025

Merge activity

  • Dec 9, 4:18 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Dec 9, 4:18 AM UTC: Dunqing added this pull request to the Graphite merge queue.
  • Dec 9, 4:24 AM UTC: The Graphite merge queue couldn't merge this PR because it was not satisfying all requirements (Failed CI: 'Test NAPI').
  • Dec 9, 4:38 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Dec 9, 4:38 AM UTC: leaysgur added this pull request to the Graphite merge queue.
  • Dec 9, 4:39 AM UTC: Merged by the Graphite merge queue.

…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`
@graphite-app graphite-app bot force-pushed the 12-09-refactor_oxfmt_use_worker_threads_by_tinypool_for_formatfile_ branch from c9770b9 to 6f3aaba Compare December 9, 2025 04:19
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 9, 2025
@leaysgur leaysgur added the 0-merge Merge with Graphite Merge Queue label Dec 9, 2025
@graphite-app graphite-app bot merged commit 6f3aaba into main Dec 9, 2025
33 of 34 checks passed
@graphite-app graphite-app bot deleted the 12-09-refactor_oxfmt_use_worker_threads_by_tinypool_for_formatfile_ branch December 9, 2025 04:39
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 9, 2025
Copilot AI pushed a commit that referenced this pull request Dec 10, 2025
…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`
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-formatter Area - Formatter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants