ruff/crates/ruff_cli/src
Charlie Marsh 0236e0751c
Avoid sorting all paths in the format command (#8181)
## Summary

Related to https://github.com/astral-sh/ruff/issues/8135.

If we're not printing a `--diff`, or a summary of `--check` changes, we
can avoid sorting the list of results. Further, when sorting, we only
need to sort a small subset of the entries, in the common case (i.e., in
general, it's much more likely that a file is formatted than not).

## Test Plan

Local benchmarks suggest a 5-10% speedup on the cached behavior:

```
❯ hyperfine --warmup 3 "./target/release/ruff format ../airflow" "./target/release/sort format ../airflow"
Benchmark 1: ./target/release/ruff format ../airflow
  Time (mean ± σ):      70.3 ms ±   5.2 ms    [User: 52.1 ms, System: 59.0 ms]
  Range (min … max):    68.3 ms … 101.7 ms    42 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Benchmark 2: ./target/release/sort format ../airflow
  Time (mean ± σ):      66.0 ms ±   1.4 ms    [User: 48.3 ms, System: 58.4 ms]
  Range (min … max):    64.7 ms …  71.8 ms    44 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Summary
  './target/release/sort format ../airflow' ran
    1.07 ± 0.08 times faster than './target/release/ruff format ../airflow'
```
2023-10-24 20:54:06 +00:00
..
bin Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00
commands Avoid sorting all paths in the format command (#8181) 2023-10-24 20:54:06 +00:00
snapshots Add ruff version with long version display (#8034) 2023-10-20 14:07:41 -05:00
args.rs Un-hide the ruff format command (#8167) 2023-10-24 09:54:28 -04:00
cache.rs Avoid loading files for cached format results (#8134) 2023-10-23 12:29:13 +01:00
diagnostics.rs Add caching to formatter (#8089) 2023-10-23 09:43:08 +01:00
lib.rs Remove experimental formatter warning (#8148) 2023-10-24 01:26:29 +00:00
panic.rs Disallow unreachable_pub (#4314) 2023-05-11 18:00:00 -04:00
printer.rs Avoid failed assertion when showing fixes from stdin (#8029) 2023-10-17 21:50:39 -04:00
resolve.rs Rename ConfigProcessor to ConfigurationTransformer (#7536) 2023-09-20 14:17:06 +00:00
stdin.rs Move stdin formatting to its own command file (#6981) 2023-08-29 16:06:10 +00:00
version.rs Add ruff version with long version display (#8034) 2023-10-20 14:07:41 -05:00