[PATCH] D91051: [clangd] Improve clangd-indexer performance
Aleksandr Platonov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 9 00:15:43 PST 2020
ArcsinX created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman.
Herald added a project: clang.
ArcsinX requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
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
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91051
Files:
clang-tools-extra/clangd/indexer/IndexerMain.cpp
Index: clang-tools-extra/clangd/indexer/IndexerMain.cpp
===================================================================
--- clang-tools-extra/clangd/indexer/IndexerMain.cpp
+++ clang-tools-extra/clangd/indexer/IndexerMain.cpp
@@ -43,6 +43,19 @@
std::unique_ptr<FrontendAction> create() override {
SymbolCollector::Options Opts;
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);
+ if (Files.count(*AbsPath) != 0)
+ return false; // Skip already processed files.
+ Files.insert(*AbsPath);
+ return true;
+ };
return createStaticIndexingAction(
Opts,
[&](SymbolSlab S) {
@@ -56,7 +69,7 @@
}
},
[&](RefSlab S) {
- std::lock_guard<std::mutex> Lock(SymbolsMu);
+ std::lock_guard<std::mutex> Lock(RefsMu);
for (const auto &Sym : S) {
// Deduplication happens during insertion.
for (const auto &Ref : Sym.second)
@@ -64,7 +77,7 @@
}
},
[&](RelationSlab S) {
- std::lock_guard<std::mutex> Lock(SymbolsMu);
+ std::lock_guard<std::mutex> Lock(RelsMu);
for (const auto &R : S) {
Relations.insert(R);
}
@@ -82,9 +95,13 @@
private:
IndexFileIn &Result;
+ std::mutex FilesMu;
+ llvm::StringSet<> Files;
std::mutex SymbolsMu;
SymbolSlab::Builder Symbols;
+ std::mutex RefsMu;
RefSlab::Builder Refs;
+ std::mutex RelsMu;
RelationSlab::Builder Relations;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91051.303761.patch
Type: text/x-patch
Size: 1830 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201109/da0f7452/attachment-0001.bin>
More information about the cfe-commits
mailing list