Skip to content

perf: format files in batches on the Wasm plugin's threads - #1476

Merged
dsherret merged 1 commit into
mainfrom
perf-format-batches
Nov 29, 2026
Merged

dsherret merged 1 commit into
mainfrom
perf-format-batches

Conversation

@dsherret

@dsherret dsherret commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Stacked on #1475.

#1475 still sends each file to a Wasm instance's thread and waits for it on the runtime's single thread. This has the instance threads take the files from a shared queue instead, so the runtime thread does a little work for each batch of files rather than for every file.

  • run_parallelized puts the files a single Wasm plugin formats in their entirety in a queue. For each permit it gets, it runs a batch on an instance's thread that formats files from the queue for up to 100 ms, then gives back the permit so throttling the CPU still works. It doesn't start more batches than there are files left, so formatting a few files doesn't create an instance for each permit.
  • Per-file config overrides are worked out when the queue is made and given to the plugin with each file, so FormatThreadRequest no longer has one.
  • Errors are logged where they happen and counted, like before. A file that has the plugin restarted (ex. it panicked) stops its batch, and that file alone is retried on a new instance. If it fails again, it's reported as a critical error and formatting stops, the same as before. When the command says to stop (--fail-fast), the other batches stop after their current file.
  • The warning for a file that's slow to format still works: the runtime thread checks the batch's current file every second.
  • InitializedPlugin::run_on_format_thread now returns Result<()>, and has_format_thread says whether a plugin supports it. Process plugins, files formatted by several plugins, --lines, and files that might be formatted because of their shebang line still go through the per-file path.

dprint check --list-different --incremental=false with @dprint/tidy (Windows), on 21,073 files from vite, storybook and rolldown, compared with #1475:

Files Threads Before After
As checked out 32 463 ms 451 ms
Already formatted 32 381 ms 355 ms
As checked out 16 511 ms 468 ms
As checked out 8 733 ms 605 ms

The gain is larger with fewer threads. The files check reports and the files fmt produces, with @dprint/tidy and with the standard plugins, are the same as before.

@dsherret
dsherret added this pull request to stack #1477 November 28, 2026 15:09
@dsherret
dsherret force-pushed the perf-format-batches branch from 0878458 to 3171948 Compare November 29, 2026 17:56
Base automatically changed from perf-format-on-instance-thread to main November 29, 2026 17:57
@dsherret
dsherret force-pushed the perf-format-batches branch from 3171948 to cc86d59 Compare November 29, 2026 17:57
@dsherret
dsherret merged commit 6ebde9f into main Nov 29, 2026
4 checks passed
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.

1 participant