rust-lang / rust-lang/rust-clippy

Re-engineering clippy for Performance

Open
#1,380 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-an-interesting-project E-hard L-perf S-needs-discussion
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

While looking at reducing memory cost for compiling clippy (and reducing LintPasses in the process), I came upon an idea that could improve performance quite a bit. Currently, we're doing the same thing over and over – for example there must be at least eight macro checks for every expression visited, and we look at visibility and/or parents at least three times. If we could make clippy's architecture more streamy and cache intermediate results, we could reduce those checks and get some nice performance improvements.

Now you may be asking: If this is so great, why haven't we done it already? First, there's obviously a cost. In this new model, lints would be much more coupled. There would be only two passes (one ClippyEarlyPass and one ClippyLatePass – or perhaps we could even reduce this to one pass that implements both early and late pass?), which would implement the logic for all lints, calling out to specific checks. For example, we'd visit an expression, and only go into certain lint methods depending on the type. We could also cache some information (e.g. parent, macro expansion information) within the Pass object, lazily loaded when needed and reused while visiting the node.

Perhaps we could reduce our current lints to consistently named functions and have a script that generates the LintPass by collecting the existing functions and emitting calls. This would probably also reduce compile time – and the chance for errors because of missing passes.

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 tracing ClippyEarlyPass and ClippyLatePass and how their lint methods are invoked during expression visits. Compare the repeated macro, visibility, and parent checks described in the issue, then assess where Pass-level caching could apply. Done would be a decided architecture and migration plan for consolidating passes and generating lint dispatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.