Repository navigation
perf: read, format and handle a file on the Wasm plugin's thread - #1475
Merged
Merged
Conversation
dsherret
force-pushed
the
perf-format-on-instance-thread
branch
from
November 29, 2026 17:56
6211e9e to
f962172
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1474.
Each file went through the runtime's single thread between every step: it was read on a blocking thread, sent to a Wasm instance's thread to be formatted, and, when it changed, sent to another blocking thread for the command to handle (ex. write it or log it). With fast plugins the runtime thread is what limits how fast files are formatted, so these round trips add up.
This adds
InitializedPlugin::run_on_format_thread, which runs a job on the thread the plugin formats on and gives the job a way to format there. Wasm plugins implement it, andrun_parallelizeduses it when a single Wasm plugin formats the entire file, so reading, formatting, making the format stable and calling the command's callback all happen on the instance's thread and the runtime thread only sends the job and waits for it. That's two thread hops per file instead of up to six.The usual way is still used for process plugins, files formatted by more than one plugin,
--lines, and extensionless files that might be formatted because of their shebang line, since the path given to the plugin depends on the file's text there. Formatting embedded text with other plugins still goes through the runtime thread like before. A job is run again on a new instance when the plugin panics, the same way a format request is.dprint check --list-different --incremental=falsewith@dprint/tidyon 32 threads (Windows), on 21,073 files from vite, storybook and rolldown (on top of #1474):The list of files
checkreports with@dprint/tidyand with the standard plugins, and the filesfmtproduces with the standard plugins, are the same as before.