Skip to content

Commit e0175f8

Browse files
committed
Document how to benchmark with lintcheck --perf
Introducing a new chapter to the book, known as "Benchmarking Clippy". It explains the benchmarking capabilities of lintcheck --perf and gives a concrete example on how benchmark and compare a PR with master
1 parent 2c51951 commit e0175f8

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

Diff for: book/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- [Updating the Changelog](development/infrastructure/changelog_update.md)
3131
- [Release a New Version](development/infrastructure/release.md)
3232
- [The Clippy Book](development/infrastructure/book.md)
33+
- [Benchmarking Clippy](development/infrastructure/benchmarking.md)
3334
- [Proposals](development/proposals/README.md)
3435
- [Roadmap 2021](development/proposals/roadmap-2021.md)
3536
- [Syntax Tree Patterns](development/proposals/syntax-tree-patterns.md)

Diff for: book/src/development/infrastructure/benchmarking.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Benchmarking Clippy
2+
3+
Benchmarking Clippy is similar to using our Lintcheck tool, in fact, it even
4+
uses the same tool! Just by adding a `--perf` flag it will transform Lintcheck
5+
into a very simple but powerful benchmarking tool!
6+
7+
It requires having the [`perf` tool][perf] installed, as `perf` is what's actually
8+
profiling Clippy under the hood.
9+
10+
The lintcheck `--perf` tool generates a series of `perf.data` in the
11+
`target/lintcheck/sources/<package>-<version>` directories. Each `perf.data`
12+
corresponds to the package which is contained.
13+
14+
Lintcheck uses the `-g` flag, meaning that you can get stack traces for richer
15+
analysis, including with tools such as [flamegraph][flamegraph-perf]
16+
(or [`flamegraph-rs`][flamegraph-rs]).
17+
18+
Currently, we only measure instruction count, as it's the most reproducible metric
19+
and rustc-perf also considers it the main number to focus on.
20+
21+
## Benchmarking a PR
22+
23+
Having a benchmarking tool directly implemented into lintcheck gives us the
24+
ability to benchmark any given PR just by making a before and after
25+
26+
Here's the way you can get into any PR, benchmark it, and then benchmark
27+
`master`.
28+
29+
The first `perf.data` will not have any numbers appended, but any subsequent
30+
benchmark will be written to `perf.data.number` with a number growing for 0.
31+
All benchmarks are compressed so that you can
32+
33+
```bash
34+
git fetch upstream pull/<PR_NUMBER>/head:<BRANCH_NAME>
35+
git switch BRANCHNAME
36+
37+
# Bench
38+
cargo lintcheck --perf
39+
40+
# Get last common commit, checkout that
41+
LAST_COMMIT=$(git log BRANCHNAME..master --oneline | tail -1 | cut -c 1-11)
42+
git switch -c temporary $LAST_COMMIT
43+
44+
# We're now on master
45+
46+
# Bench
47+
cargo lintcheck --perf
48+
perf diff ./target/lintcheck/sources/CRATE/perf.data ./target/lintcheck/sources/CRATE/perf.data.0
49+
```
50+
51+
52+
[perf]: https://perfwiki.github.io/main/
53+
[flamegraph-perf]: https://github.com/brendangregg/FlameGraph
54+
[flamegraph-rs]: https://github.com/flamegraph-rs/flamegraph
55+
[rustc-perf]:

0 commit comments

Comments
 (0)