From dad804a193edf092322d80bb404fabb2f6f2c888 Mon Sep 17 00:00:00 2001 From: Aleksandr Platonov Date: Wed, 11 Nov 2020 14:29:03 +0300 Subject: [PATCH] [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 --- clang-tools-extra/clangd/indexer/IndexerMain.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clangd/indexer/IndexerMain.cpp b/clang-tools-extra/clangd/indexer/IndexerMain.cpp index 4622423..fd8404b 100644 --- a/clang-tools-extra/clangd/indexer/IndexerMain.cpp +++ b/clang-tools-extra/clangd/indexer/IndexerMain.cpp @@ -43,6 +43,16 @@ public: std::unique_ptr 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 Lock(FilesMu); + return Files.insert(*AbsPath).second; // Skip already processed files. + }; return createStaticIndexingAction( Opts, [&](SymbolSlab S) { @@ -56,7 +66,7 @@ public: } }, [&](RefSlab S) { - std::lock_guard Lock(SymbolsMu); + std::lock_guard Lock(RefsMu); for (const auto &Sym : S) { // Deduplication happens during insertion. for (const auto &Ref : Sym.second) @@ -64,7 +74,7 @@ public: } }, [&](RelationSlab S) { - std::lock_guard Lock(SymbolsMu); + std::lock_guard Lock(RelsMu); for (const auto &R : S) { Relations.insert(R); } @@ -82,9 +92,13 @@ public: 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; }; -- 2.7.4