[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

llvm-svn: 346319
This commit is contained in:
Haojian Wu 2018-11-07 14:59:24 +00:00
parent 8f07efc7c5
commit f761a2c620
3 changed files with 7 additions and 1 deletions

View File

@ -367,7 +367,7 @@ bool SymbolCollector::handleDeclOccurence(
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.

View File

@ -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

View File

@ -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();