https://github.com/orgads created 
https://github.com/llvm/llvm-project/pull/244530

IndexBuilder::build() reserves the inverted index for the tokens it is going to 
have. It added RestrictedCCDocs.size() to that, which is the number of symbols 
that are indexed for code completion, although these are the posting list of a 
single token.

On a project with 195000 symbols, the inverted index of the background index 
had 262144 buckets for 50295 tokens. With the right number it has half of them, 
and the working set of clangd is 12 MB smaller: 474 MB instead of 486 MB.

Assisted-by: Claude Code

>From 1631bf2830efbacc33d798ae3d21591d059d699c Mon Sep 17 00:00:00 2001
From: Orgad Shaneh <[email protected]>
Date: Fri, 20 Nov 2026 08:55:43 +0200
Subject: [PATCH] [clangd] Don't reserve a token for each code completion
 symbol in Dex

IndexBuilder::build() reserves the inverted index for the tokens it is
going to have. It added RestrictedCCDocs.size() to that, which is the
number of symbols that are indexed for code completion, although these
are the posting list of a single token.

On a project with 195000 symbols, the inverted index of the background
index had 262144 buckets for 50295 tokens. With the right number it has
half of them, and the working set of clangd is 12 MB smaller: 474 MB
instead of 486 MB.

Assisted-by: Claude Code
---
 clang-tools-extra/clangd/index/dex/Dex.cpp | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clangd/index/dex/Dex.cpp 
b/clang-tools-extra/clangd/index/dex/Dex.cpp
index 179d8c4da0b3ec..616304b6b314c9 100644
--- a/clang-tools-extra/clangd/index/dex/Dex.cpp
+++ b/clang-tools-extra/clangd/index/dex/Dex.cpp
@@ -84,12 +84,10 @@ class IndexBuilder {
 
   // Assemble the final compressed posting lists for the added symbols.
   llvm::DenseMap<Token, PostingList> build() && {
-    llvm::DenseMap<Token, PostingList> Result(/*InitialReserve=*/
-                                              TrigramDocs.size() +
-                                              RestrictedCCDocs.size() +
-                                              TypeDocs.size() +
-                                              ScopeDocs.size() +
-                                              ProximityDocs.size());
+    // RestrictedCCDocs is the posting list of a single token.
+    llvm::DenseMap<Token, PostingList> Result(
+        /*InitialReserve=*/TrigramDocs.size() + !RestrictedCCDocs.empty() +
+        TypeDocs.size() + ScopeDocs.size() + ProximityDocs.size());
     // Tear down intermediate structs as we go to reduce memory usage.
     // Since we're trying to get rid of underlying allocations, clearing the
     // containers is not enough.

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to