Author: hokein Date: Wed Nov 7 06:59:24 2018 New Revision: 346319 URL: http://llvm.org/viewvc/llvm-project?rev=346319&view=rev Log: [clangd] Drop namespace references in the index.
Summary: Namespace references is less useful compared with other symbols, and they contribute large part of the index. This patch drops them. The number of refs is reduced from 5.4 million to 4.7 million. | | Before | After | |file size | 78 MB | 71MB | |memory | 330MB | 300MB| Reviewers: sammccall Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54202 Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.h clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=346319&r1=346318&r2=346319&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original) +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Wed Nov 7 06:59:24 2018 @@ -367,7 +367,7 @@ bool SymbolCollector::handleDeclOccurenc return true; if (!shouldCollectSymbol(*ND, *ASTCtx, Opts)) return true; - if (CollectRef && + if (CollectRef && !isa<NamespaceDecl>(ND) && (Opts.RefsInHeaders || SM.getFileID(SpellingLoc) == SM.getMainFileID())) DeclRefs[ND].emplace_back(SpellingLoc, Roles); // Don't continue indexing if this is a mere reference. Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.h?rev=346319&r1=346318&r2=346319&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/SymbolCollector.h (original) +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.h Wed Nov 7 06:59:24 2018 @@ -60,6 +60,9 @@ public: bool CountReferences = false; /// The symbol ref kinds that will be collected. /// If not set, SymbolCollector will not collect refs. + /// Note that references of namespace decls are not collected, as they + /// contribute large part of the index, and they are less useful compared + /// with other decls. RefKind RefFilter = RefKind::Unknown; /// If set to true, SymbolCollector will collect all refs (from main file /// and included headers); otherwise, only refs from main file will be Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=346319&r1=346318&r2=346319&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Wed Nov 7 06:59:24 2018 @@ -443,6 +443,8 @@ TEST_F(SymbolCollectorTest, Refs) { }; class $bar[[Bar]]; void $func[[func]](); + + namespace $ns[[NS]] {} // namespace ref is ignored )"); Annotations Main(R"( class $bar[[Bar]] {}; @@ -474,6 +476,7 @@ TEST_F(SymbolCollectorTest, Refs) { HaveRanges(Main.ranges("bar"))))); EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "func").ID, HaveRanges(Main.ranges("func"))))); + EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(Symbols, "NS").ID, _)))); // Symbols *only* in the main file (a, b, c) had no refs collected. auto MainSymbols = TestTU::withHeaderCode(SymbolsOnlyInMainCode.code()).headerSymbols(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits