Search code examples
clang-tidyclangd

Why is clang-tidy in clangd so much faster than (run-)clang-tidy itself?


I have a fairly large project with lots & large headers that are included. Running clang-tidy on a single source file takes 10+ minutes. In contrast to that clang-tidy findings in clangd show up almost immediately.

I expect clangd to be faster due to caching, multithreading, but not <1 second vs 10 minutes.

Are there e.g. any expensive rules that are disabled for clangd usage or is some accuracy sacrified for performance?


Solution

  • clang-tidy perform all checks on all included headers (though it supresses diagnostics from system headers by default), whereas clangd only checks current files.

    Although clangd also reads all included headers for tasks like building AST, these tasks are executed much faster than static analysis.

    PS: I have implemented a clangd wrapper designed as a faster alternative to clang-tidy. Feel free to give it a try in your CI scripts.