Repository navigation
perf: exit instead of unwinding after a successful run - #1388
Merged
Merged
Conversation
On macOS, returning from `main` frees every loaded Wasm module, and wasmtime deregisters each function's unwind info from libunwind one at a time while doing it. With 12 plugins that took 435 ms of a 570 ms single-file run, and it grows faster than linearly with the plugin count (0, 9, 56 and 435 ms at 1, 3, 6 and 12 plugins). The error arm and the language server already end the process with `std::process::exit`. Do the same on success. Everything a run has to do is finished inside `run()`: files are written as they are formatted, the incremental cache is saved by the command, output is written and the plugins are shut down. Only the process teardown is skipped. Adds tests/fast_exit.rs, which runs the built binary: the formatted file and an incremental cache entry exist after the process exits, stdout without a trailing newline is complete, and a run with nothing to format exits 0. Exiting just before the incremental cache is written makes the first test fail.
dsherret
approved these changes
Oct 22, 2026
dsherret
left a comment
Member
There was a problem hiding this comment.
Nice catch! Thanks!
I'll look into ways of catching this in the future to ensure it doesn't regress. This previously used to happen on Windows too.
zachbornheimer
added a commit
to zachbornheimer/dev-profile
that referenced
this pull request
Oct 23, 2026
dprint/dprint#1388 (our exit-after-success patch) was merged and then reverted by #1391, which fixes the same macOS cost at its source by not generating native unwind info for wasm plugins (0.64.2). Measured on this machine: single-file stdin format 19 ms on 0.64.3 against 72 ms on the fork, whole-repo fmt equal. Upstream ships Linux and Windows assets, so the per-OS pin (cc4fb6e) is no longer needed and is reverted with the fork pin.
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.
Closes #1387
Exits the process once
run()succeeds instead of returning frommain. The error arm and the language server already do this.Returning from
mainfrees every loaded Wasm module. On macOS wasmtime deregisters each function's unwind info from libunwind one at a time while doing that, so with 12 plugins it took 435 ms of a 570 ms single-file run (0, 9, 56 and 435 ms at 1, 3, 6 and 12 plugins). Everything a run has to do is finished insiderun()before this point: files are written as they are formatted, the incremental cache is saved by the command, output is written and plugins are shut down byclear_and_shutdown_initialized().Measurements
macOS arm64, 12 plugins, release builds, CPU time of the process (user + sys) so a busy machine doesn't skew it, interleaved rounds, medians:
fmt --stdin, one file (25 rounds)fmtwhole repo, 3217 files, already formatted (6 rounds)On an idle machine, wall time, medians of 4 interleaved rounds: whole repo 4.81 s -> 3.82 s (unformatted) and 3.07 s -> 2.04 s (formatted); single file 643-923 ms -> 58-180 ms.
Linux (aarch64, glibc, in Docker) shows no difference (single file 60 ms -> 62 ms wall, whole repo 2850 ms -> 2831 ms). Windows wasn't measured.
Test
tests/fast_exit.rsruns the built binary and checks what has to be finished before the process exits: the formatted file and an incremental cache entry are on disk,--stdinoutput without a trailing newline is complete, and a run with nothing to format exits 0. Exiting just before the incremental cache is written (incremental_file.write()) makes the first test fail, so it fails if that work ever moves into a destructor.Checked
--log-level debugoutput of a single-file run are the same before and after.execprocess plugin the plugin process is gone after the run, and the final terminal output on a TTY is byte-identical.cargo fmt --checkandcargo test -p dprint --test fast_exitpass.cargo clippy -p dprint --all-targetsreports nothing in the changed files; it fails onmainalready atcommands/editor/mod.rs:1249(reversed_empty_ranges).Not checked
dprint fmt/checkpaths were run; other successful commands take the same exit.