-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
High overhead #6353
Comments
@TomFryersMidsummer thanks fort the report. What version of rustfmt are you using? How are you calling rustfmt in your scripts? Do you have a Also, running rustfmt on |
I'm using I’m passing source code to I haven’t profiled Rustfmt, but I have noticed that it’s nearly twice as fast if I specify the toolchain manually, with |
Better still: |
Largely, it looks like this is caused by this Rustup issue. But it would still be nice to be down closer to Ruff when calling the binary without the wrapper. |
That's all very helpful info! |
are you making those invocations sequentially or in parallel? in the latter, are you invoking rustfmt multiple times and passing it one file each time or invoking rustfmt once and passing the full list of file paths? I'd imagine there's some level of bootstrapping overhead each time that establishes a runtime floor, but unless there's some really straightforward low hanging fruit I don't think this is something we can really do much about, or at least I don't think we've got the spare capacity to try to optimize away a couple dozen milliseconds |
In parallel.
I'm passing it one file each time on standard input. I couldn't find a way to get Rustfmt to take more than one file on standard input. I could save everything to temporary files on tmpfs, pass this list to Rustfmt, then read them all back, but that's a bit of a silly workaround, with its own overheads. I could also concatenate them, with some special comment as a separator, and try to split them back up, but that doesn't work if a file contains syntax errors. |
Rustfmt has quite high per-run overhead. For example, running repeated benchmarks on my machine gives the following means:
echo | rustfmt
: 48 mscat lib.rs | rustfmt
: 55 msHere,
lib.rs
is rustfmt’s own 670-line file. 55 ms for 670 lines is pretty good! But 48 ms to format the empty string doesn’t seem quite so speedy.Some other formatters have a much lower overhead:
ruff format -
, for instance, takes 4 ms. Although some are far worse:echo | prettier --parser babel
takes 230 ms.This can make quite a difference when using
rustfmt
in scripts. (I have a script that formats proptest function bodies, which callsrustfmt
452 times.)The text was updated successfully, but these errors were encountered: