[clangd] Improve clangd-indexer performance

This is a try to improve clangd-indexer tool performance:
- avoid processing already processed files.
- use different mutexes for different entities (e.g. do not block insertion of references while symbols are inserted)

Results for LLVM project indexing:
- before: ~30 minutes
- after: ~10 minutes

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D91051
This commit is contained in:
Aleksandr Platonov 2020-11-11 14:29:03 +03:00
parent eae2d63571
commit dad804a193
1 changed files with 16 additions and 2 deletions

View File

@ -43,6 +43,16 @@ public:
std::unique_ptr<FrontendAction> create() override { std::unique_ptr<FrontendAction> create() override {
SymbolCollector::Options Opts; SymbolCollector::Options Opts;
Opts.CountReferences = true; Opts.CountReferences = true;
Opts.FileFilter = [&](const SourceManager &SM, FileID FID) {
const auto *F = SM.getFileEntryForID(FID);
if (!F)
return false; // Skip invalid files.
auto AbsPath = getCanonicalPath(F, SM);
if (!AbsPath)
return false; // Skip files without absolute path.
std::lock_guard<std::mutex> Lock(FilesMu);
return Files.insert(*AbsPath).second; // Skip already processed files.
};
return createStaticIndexingAction( return createStaticIndexingAction(
Opts, Opts,
[&](SymbolSlab S) { [&](SymbolSlab S) {
@ -56,7 +66,7 @@ public:
} }
}, },
[&](RefSlab S) { [&](RefSlab S) {
std::lock_guard<std::mutex> Lock(SymbolsMu); std::lock_guard<std::mutex> Lock(RefsMu);
for (const auto &Sym : S) { for (const auto &Sym : S) {
// Deduplication happens during insertion. // Deduplication happens during insertion.
for (const auto &Ref : Sym.second) for (const auto &Ref : Sym.second)
@ -64,7 +74,7 @@ public:
} }
}, },
[&](RelationSlab S) { [&](RelationSlab S) {
std::lock_guard<std::mutex> Lock(SymbolsMu); std::lock_guard<std::mutex> Lock(RelsMu);
for (const auto &R : S) { for (const auto &R : S) {
Relations.insert(R); Relations.insert(R);
} }
@ -82,9 +92,13 @@ public:
private: private:
IndexFileIn &Result; IndexFileIn &Result;
std::mutex FilesMu;
llvm::StringSet<> Files;
std::mutex SymbolsMu; std::mutex SymbolsMu;
SymbolSlab::Builder Symbols; SymbolSlab::Builder Symbols;
std::mutex RefsMu;
RefSlab::Builder Refs; RefSlab::Builder Refs;
std::mutex RelsMu;
RelationSlab::Builder Relations; RelationSlab::Builder Relations;
}; };