rust-lang / rust-lang/rust-clippy

[Perf] Most time-consuming lints

Open
#14,707 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-an-interesting-project G-performance-project
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Expanded from this thread on Zulip.

I've come up with a way to isolate lints, and run them individually in a lintcheck --perf run. Here are the results:

The five lints with the highest impact are (in order or importance)

  • ctfe::ClippyCtfe with 1.05e9 instructions
  • minmax::MinMaxPass with 0.94e9
  • needless_late_init::NeedlessLateInit
  • methods::Methods with 0.92e9
  • explicit_write::ExplicitWrite with 0.90e9

Here they are represented by the five biggest peaks:

Graph on lint instruction count

Note that I could only perform the experiment on 326 out of the 344 existing passes because of experiment issues, there may exist hidden performance-intensive lints. Still, we can focus on fixing those five before any others.

Spiritual successor to https://github.com/rust-lang/rust-clippy/issues/12188

HOW TO REPRODUCE

  • Clone my isolate-lints branch (or manually copy-paste the changes into your branch).

Then, ideally get a server to do this work because it will be like 10 hours of PC work (ideally without any background processes).

  • Run pypy.py, it will extract all passes from clippy_lints/src/lib.rs into about 350 files.
  • Check the last file and remove that unnecessary }, if you don't do this it will result in a compilation file in that last pass.

See lib.rs? It has an include!(var!(SELECTED_LINT_FILE)), we'll use that.

The following code block is written in bash, translate it into your preferred terminal language.

for f in ./*.txt; do
    SELECTED_LINTS_FILE=../../$f cargo lintcheck --perf --crates-toml=lintcheck/tokio_benchmark.toml && rm -r target/release/ ;
done

It will generate 344 perf.data files, we now need to convert this into readable scripts.

for f in ./perf.data*; do
  perf script -i $f > scripted/$f.scripted
done

This will generate about 344 perf.x.scripted. You can now use data-crunch/pypy.py to get the results (note that if the python data-crunch/pypy.py prints 37, you'll have to go to 38.txt to find which lint that corresponds to because the file-making script starts from 1.txt)

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 with clippy_lints/src/lib.rs and the five named passes: ctfe::ClippyCtfe, minmax::MinMaxPass, needless_late_init::NeedlessLateInit, methods::Methods, and explicit_write::ExplicitWrite. Reproduce the measurements with the isolate-lints branch, lintcheck/tokio_benchmark.toml, and data-crunch/pypy.py, then compare perf results after addressing the highest-impact passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
devtools, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.