Skip to content

perf(oxfmt): use worker_threads for tinypool again - #28787

Merged
leaysgur merged 1 commit into
mainfrom
11-04-refactor_oxfmt_use_worker_threads_for_tinypool_again
Nov 4, 2026
Merged

leaysgur merged 1 commit into
mainfrom
11-04-refactor_oxfmt_use_worker_threads_for_tinypool_again

Conversation

@leaysgur

@leaysgur leaysgur commented Nov 4, 2026

Copy link
Copy Markdown
Member

napi-rs/napi-rs#3670 fixed deadlock issue in our usecase, so now we can use it again.

leaysgur commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

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 changes, fast-track this PR to the front of 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.

@github-actions github-actions Bot added A-cli Area - oxlint / oxfmt common CLI behavior: flags, ignore files, oxc_config A-formatter Area - Formatter (oxfmt). Add F-* labels for details labels Nov 4, 2026
@leaysgur leaysgur changed the title refactor(oxfmt): use worker_threads for tinypool again perf(oxfmt): use worker_threads for tinypool again Nov 4, 2026
@leaysgur
leaysgur merged commit 07627f7 into main Nov 4, 2026
31 checks passed
@leaysgur
leaysgur deleted the 11-04-refactor_oxfmt_use_worker_threads_for_tinypool_again branch November 4, 2026 01:22
leaysgur added a commit that referenced this pull request Nov 4, 2026
Follow-up to #28517 and #28787.

When the CLI needs Prettier and no worker is free, it spawns one worker,
up to `--threads` (default: the number of logical CPU cores). Spawned
workers stay alive for later files. Before this PR, the first file that
needs Prettier starts every worker.

## Results

`oxfmt --check` on AMD Ryzen 9 7940HS (16 threads), `main` at
8432de6, 30 runs per build. Values are means.

| Target | Node.js 24.21.0 | Node.js 26.12.1 |
|---|---:|---:|
| Synthetic: 1 Vue + 70 TS files | -41.5 ms (-26.7%) | -24.9 ms (-20.1%)
|
|
[toeverything/AFFiNE](https://github.com/toeverything/AFFiNE/tree/fbf2cebfa0)
| -61.0 ms (-18.6%) | -43.4 ms (-15.0%) |
| [Kong/insomnia](https://github.com/Kong/insomnia/tree/88ae88d6e5) |
-32.6 ms (-9.3%) | -20.7 ms (-6.8%) |
| [vuejs/core](https://github.com/vuejs/core/tree/0ff253bfba) | -22.8 ms
(-7.6%) | -16.9 ms (-6.5%) |
| [antfu/vitesse](https://github.com/antfu/vitesse/tree/a8785264f8) |
-19.9 ms (-8.0%) | -12.5 ms (-5.9%) |
|
[immich-app/immich](https://github.com/immich-app/immich/tree/afc5a2291e)
| -23.5 ms (-6.4%) | -9.0 ms (-2.8%) |
| [wxt-dev/wxt](https://github.com/wxt-dev/wxt/tree/f8ed652912) | -16.8
ms (-5.0%) | -4.2 ms (within noise) |

The other 9 targets are within noise on both versions: 2 synthetic
targets and tldraw, elk, starlight, zustand, outline, shoelace, and
social-app. The gain is largest when a project needs only a few Prettier
workers.

AI disclosure: the patch and the measurements were done with Claude
Code, and I reviewed them.

---------

Co-authored-by: leaysgur <6259812+leaysgur@users.noreply.github.com>
graphite-app Bot pushed a commit that referenced this pull request Nov 6, 2026
# Oxlint
### 🚀 Features

- 4a52ba2 oxlint: Discover tsrs for type-aware linting (#28751) (camc314)
- b7d2c75 linter/eslint/no-redeclare: Add `ignoreDeclarationMerge` option (#28816) (Cam McHenry)

### 🐛 Bug Fixes

- fa66fde oxlint,oxfmt: Resolve Vite+ config root from the config file directory (#28801) (MK (fengmk2))
- 2091564 linter/jsdoc/require-param: Ignore enclosing function JSDoc (#28866) (camc314)
- c6ec50b linter/react/only-export-components: Classify JSX values as non-components (#28761) (camc314)
- 3c051ab linter/vitest/prefer-called-exactly-once-with: Preserve neighboring code in autofix (#28864) (camc314)
- 674b962 linter/eslint/no-misleading-character-class: Use lazy regex for combining marks (#28822) (Sysix)
- 838d339 linter/vitest/prefer-called-exactly-once-with: Avoid panic on non-ASCII text (#28850) (YT)
- 8d24c26 linter/jsx-a11y/aria-role: Allow role={undefined} (#28804) (Abhay Godavarthy)
- a7143bf linter/eslint/no-restricted-imports: Respect allowTypeImports correctly for empty patterns (#28842) (Cam McHenry)
- 3d3a6f4 react-compiler: Ignore callback-local reassignments (#28820) (camc314)
- 0cc6515 linter/unicorn/prefer-type-error: Report throws in unbraced if branches (#28819) (camc314)
- ae43c80 linter/unicorn/prefer-single-call: Remove duplicate fix status (#28763) (Mikhail Baev)
- a8a621a linter/eslint/no-fallthrough: Ignore unreachable exits from infinite loops (#28755) (camc314)
- 7a17a80 linter/eslint/prefer-spread: Report calls on non-member expressions (#28753) (camc314)
- 28442f7 oxlint: Prevent --init from overwriting existing configs (#28754) (camc314)
- 0ae350d linter/unicorn/no-zero-fractions: Preserve exponent case (#28752) (camc314)
- b5b3f3f linter/eslint/no-misleading-character-class: Detect more combining characters (#28733) (Sysix)

### ⚡ Performance

- 74d50c1 linter: Overlap import graph batches instead of polling on a pool worker (#28323) (Dunqing)
# Oxfmt
### 💥 BREAKING CHANGES

- 00d1a67 oxfmt: [**BREAKING**] Format `parser:vue` files by `oxc_formatter_htmlish` (#28848) (leaysgur)

### 🚀 Features

- 9a81e58 formatter_htmlish: Format Vue templates (#28847) (leaysgur)
- 119d82f formatter: Format a template's expressions and handlers as `JsRoot` (#28846) (leaysgur)

### 🐛 Bug Fixes

- fa66fde oxlint,oxfmt: Resolve Vite+ config root from the config file directory (#28801) (MK (fengmk2))
- 4d4104d formatter_htmlish: Preserve `doctype` case in embedded (#28797) (leaysgur)
- ebfd40a formatter: Sort Tailwind calls printed as member chains (#28800) (Yuji Sugiura)
- e62e5cb formatter: Decide quotes of a Tailwind key printed as one class (#28798) (Yuji Sugiura)
- 959edc1 formatter: Don't sort templates in nested non-Tailwind calls (#28794) (Yuji Sugiura)
- 6ffbe32 formatter/jsdoc: Prevent `@tag` from being moved to the line start (#28835) (leaysgur)
- 94fbef5 formatter_css: Treat comments in `style` attr as fill items (#28832) (leaysgur)
- e4a80f7 formatter_css: Normalize selectors inside `:deep`, `:slotted` and `:local` (#28805) (leaysgur)
- 255c5cc formatter: Measure Tailwind class argument after collapsing whitespace (#28745) (Lee Jaeha / Adam)
- e6c4fef formatter: Decide template and object key layouts from collapsed Tailwind classes (#28791) (Yuji Sugiura)
- 0b44164 formatter: Decide JSX opening element layout from collapsed Tailwind class string (#28744) (Lee Jaeha / Adam)
- b8ba9ae formatter: Print decorators on rest parameters (#28731) (YT)

### ⚡ Performance

- 2766d07 oxfmt: Spawn Prettier workers on demand (#28789) (YT)
- 07627f7 oxfmt: Use worker_threads for tinypool again (#28787) (Yuji Sugiura)
leaysgur added a commit that referenced this pull request Nov 17, 2026
… 1 Tokio worker (#29728)

Fixes #29718

With 1 vCPU (e.g. GitHub Actions `ubuntu-slim`), `oxfmt` intermittently
never exits when formatting `.astro` with frontmatter or `.svelte` with
`<script>`.

### Cause

- `run_cli()` is a napi `async fn`, so it runs on a Tokio worker
- `WalkRunner::run()` blocks that thread until all files are formatted
(walk, `rx_success` loop), but only `init()` was wrapped in
`block_in_place()`
- `block_in_place()` hands the core to a new thread, but takes it back
on exit if that thread has not started yet
  - Then the CLI task keeps the only core while waiting for results
- Prettier workers call `jsTextToDoc()` via `prettier-plugin-oxfmt`,
spawned onto the same process-wide runtime
- With a single worker, nothing can run it, and its promise never
settles

Since #28787 (0.77.0), the Prettier pool uses `worker_threads`, so
`jsTextToDoc()` shares the runtime with the CLI.

### Fix

Run the whole `WalkRunner::run()` in `block_in_place()`, and remove the
now-nested one around `init()`.

### Example

Input:

```sh
# docker run --platform linux/amd64 --cpus=1 --cpuset-cpus=0 node:24.22.3
printf '{"private":true,"type":"module"}\n' > package.json
printf '{"svelte":true}\n' > .oxfmtrc.json
printf '<script>\n  let a = 1;\n</script>\n\n<div>{a}</div>\n' > a.svelte
npm i oxfmt@0.79.0 svelte
# Replace `node_modules/@oxfmt/binding-linux-x64-gnu/oxfmt.linux-x64-gnu.node` with a debug build
# of 0.79.0 (229b69b), with and without this change, then run 400 times with a 10s timeout:
#   ./node_modules/.bin/oxfmt --check a.svelte
```

Before output (3 containers x 400 runs):

```text
ok=395 hang=5
ok=399 hang=1
ok=397 hang=3
```

After output:

```text
ok=400 hang=0
ok=400 hang=0
ok=400 hang=0
```

Hung runs never close the `oxfmt::text_to_doc` span
(`OXC_LOG=oxfmt=debug`), and all threads are parked.
Setting `TOKIO_WORKER_THREADS=2` also avoids the hang (0/400) without
this change.

No playground link: this is a CLI runtime hang that depends on thread
scheduling.

---

AI disclosure: investigated and implemented with Claude Code (Claude
Opus 5.5), reviewed by the author.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - oxlint / oxfmt common CLI behavior: flags, ignore files, oxc_config A-formatter Area - Formatter (oxfmt). Add F-* labels for details

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant