This is an archive of the discontinued LLVM Phabricator instance.

[clangd][NFC] Cache ClangTidy check globs to speed up createChecks
Needs ReviewPublic

Authored by njames93 on Jan 17 2022, 5:47 PM.

Details

Reviewers
sammccall
Summary

Build a fast factory for creating clang-tidy check lists based off a glob string.

Compile Globs into a BitVector representation that can be used to build a vector of checks without having to consult the glob string. Cache these representations as most invocations will be using the same glob string.

Diff Detail

Event Timeline

njames93 created this revision.Jan 17 2022, 5:47 PM
njames93 requested review of this revision.Jan 17 2022, 5:47 PM
njames93 updated this revision to Diff 400893.Jan 18 2022, 9:55 AM

Pre-allocate both vectors

Haven't looked much in detail so apologies if my comment is stupid - can't CachedGlobList be used for this purpose? Should be a one-liner change I think.

Haven't looked much in detail so apologies if my comment is stupid - can't CachedGlobList be used for this purpose? Should be a one-liner change I think.

Not a stupid question, but CachedGlobList is doing something very different. That's just caching the result of strings when they are passed to a glob to simplify re-evaluation of the same string.
However this implementation is about avoiding the need to check any check-names when building the list of checks. It's also thread safe unlike CachedGlobList.

Happy to take a look at this, but is there a particular motive for optimizing this?
Looking at some profiles this appears to be something like 0.1-0.5ms in fairly complex configurations.

clang-tools-extra/clangd/ParsedAST.cpp
288

if it's possible, it seems like this class really wants to be a function

292

I wonder if a global map is overkill (and the locking maybe undesirable).

In practice, this is being called in a loop on a single thread (the AST worker thread), with no other calls on that thread.
The idea with caching is that the checks globs are usually the same, that is especially true for parses of the main file.

So maybe we could just use a single-entry thread_local cache, with no map and no locking?

295

why cache a bitmap instead of the vector<factory> directly?

448–449

we need to be more careful with static state than this. This adds global destructors and we need to suppress them. (e.g. by using new without delete)

njames93 updated this revision to Diff 401197.Jan 19 2022, 5:51 AM

Address comments

njames93 marked 3 inline comments as done.Jan 19 2022, 6:00 AM
njames93 updated this revision to Diff 401209.Jan 19 2022, 6:18 AM

Remove now unnecessary changes in ClangTidyModule.
Fix Cache miss reporting