Skip to content

perf: read, format and handle a file on the Wasm plugin's thread - #1475

Merged
dsherret merged 1 commit into
mainfrom
perf-format-on-instance-thread
Nov 29, 2026
Merged

dsherret merged 1 commit into
mainfrom
perf-format-on-instance-thread

Conversation

@dsherret

Copy link
Copy Markdown
Member

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, and run_parallelized uses 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=false with @dprint/tidy on 32 threads (Windows), on 21,073 files from vite, storybook and rolldown (on top of #1474):

Files Before After
As checked out (most need formatting) 543 ms 461 ms
Already formatted 411 ms 383 ms

The list of files check reports with @dprint/tidy and with the standard plugins, and the files fmt produces with the standard plugins, are the same as before.

@dsherret
dsherret added this pull request to stack #1477 November 28, 2026 15:09
Base automatically changed from perf-glob-gitignore to main November 29, 2026 17:56
@dsherret
dsherret force-pushed the perf-format-on-instance-thread branch from 6211e9e to f962172 Compare November 29, 2026 17:56
@dsherret
dsherret merged commit 7e0d4d1 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