rust-lang / rust-lang/rustfmt

High overhead

Open
#6,353 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-performance P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Rustfmt has quite high per-run overhead. For example, running repeated benchmarks on my machine gives the following means:

  • echo | rustfmt: 48 ms
  • cat lib.rs | rustfmt: 55 ms

Here, 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 calls rustfmt 452 times.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported benchmarks with echo | rustfmt and cat lib.rs | rustfmt, using rustfmt’s src/lib.rs as the mentioned larger input. Investigate where the per-run overhead comes from and measure the empty-input case again after each change. Done means a documented, reproducible reduction in startup overhead without regressing formatting behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.