clangd: Don't run slow clang-tidy checks
misc-const-correctness
shows an extreme slowdown on large files, causing a >10x regression of clangd reparse time when enabled. Checks are often inadventently enabled e.g. by misc-*
globs, as much as we wish this weren’t the case. I blocked this check in e78165f0ba1e2fbf72b36a36c8560645b69a168a, but a more systematic approach is needed.
Goals:
- don’t let slow checks into releases. We can’t assume check authors care about clangd.
- minimize feature churn between releases
- minimize maintenance toil
- document some fairly objective standard of “fast” that users and check authors can understand
Plan:
- only run “fast checks” by default, as an additional filter applied to checks specified in
.clang-tidy
etc - keep a static “fast check” list, not a “slow check” list, per goal 1.
- maintain this list by benchmarking on a known complex file (suggest
clang/lib/SemaExpr.cpp
) - addresses goal 4 - “fast” means “regresses
ParsedAST::build()
” by less than 10% - benchmarking is done by a new mode in
clangd --check
, precise within <5%. Script updates the fast list (goal 3). - avoid noise by using some debounce: add a check to fast list if measurement <8%, remove it if measurement >13%. Addresses goal 2
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (3 by maintainers)
Commits related to this issue
- [clangd] Extend --check to time clang-tidy checks, so we can block slow ones misc-const-correctness is so catastrophically slow that we need to block it from running. But we need a way to detect this... — committed to llvm/llvm-project by sam-mccall 2 years ago
- [clangd] Add option to skip per-location checks. This avoids a slow step after timing tidy checks for https://github.com/clangd/clangd/issues/1337 — committed to llvm/llvm-project by sam-mccall 2 years ago
- [clangd] Add script to maintain list of fast clang-tidy checks The plan is to intersect this list with the checks selected per config. This is not yet done, but the initial list is checked in as a ba... — committed to llvm/llvm-project by sam-mccall 2 years ago
- [clangd] Add script to maintain list of fast clang-tidy checks The plan is to intersect this list with the checks selected per config. This is not yet done, but the initial list is checked in as a ba... — committed to SNSystems/llvm-debuginfo-analyzer by sam-mccall 2 years ago
https://github.com/clangd/clangd/issues/1337#issuecomment-1770214885
That would require users to have a list available of which checks are slow. Maybe the documentation in https://clang.llvm.org/extra/clang-tidy/checks/list.html could have an extra column added for Good, Slow (with some measure of how slow maybe) or Unstable (crashes)
I’d very much like to add specific slow checks while disabling the bulk of them.
The list of clang-tidy checks considered to be slow by clangd can be found here: https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/TidyFastChecks.inc. clang-tidy also offers a flag to enable timing profiles per check to be printed with
clang-tidy --enable-check-profile
, which would probably be better in telling you which checks are slowing down your use-case specifically.Sorry for leaving this thread unattended for a long while. We iterated over this with @sam-mccall couple times offline, but forgot to leave any artifacts.
Our final conclusions were towards:
ClangTidy.EnableSlowChecks
boolean, that defaults toFalse
. (if need be we can have an orthogonal option to enable crashing-checks).The rationale for never enabling crashy checks is, in practice that just causes support requests on clangd side that we can’t maintain and degrades experience for average user to the point of having an unusable clangd until they do a through investigation (or ask for support).
This still needs us to have a separate list of “slow” checks, @sam-mccall is going to be working on getting that piece landed this week.
What do you folks think about this?
Perhaps this could take the form of a new
Allowlist
subkey under ClangTidy in the clangd config file, which does not allow globs, and explicitly enables the listed checks, overriding the performance section of the built-in blocklist.