[PATCH] D106528: [clangd] Improve performance of dex by 45-60%

Kirill Bobyrev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 22 14:17:06 PDT 2021


kbobyrev updated this revision to Diff 360970.
kbobyrev added a comment.

Add more comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106528/new/

https://reviews.llvm.org/D106528

Files:
  clang-tools-extra/clangd/index/dex/Iterator.cpp


Index: clang-tools-extra/clangd/index/dex/Iterator.cpp
===================================================================
--- clang-tools-extra/clangd/index/dex/Iterator.cpp
+++ clang-tools-extra/clangd/index/dex/Iterator.cpp
@@ -104,11 +104,19 @@
         // In this case, just terminate the process.
         if (ReachedEnd)
           return;
+        // Cache the result so that peek() is not called again as it may be
+        // quite expensive in AND with large subtrees.
+        auto Candidate = Child->peek();
         // If any child goes beyond given ID (i.e. ID is not the common item),
         // all children should be advanced to the next common item.
-        if (Child->peek() > SyncID) {
-          SyncID = Child->peek();
+        if (Candidate > SyncID) {
+          SyncID = Candidate;
           NeedsAdvance = true;
+          // Reset and try to sync again. Sync starts with the first child as
+          // this is the cheapest (smallest size estimate). This way advanceTo
+          // is called on the large posting lists once the sync point is very
+          // likely.
+          break;
         }
       }
     } while (NeedsAdvance);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106528.360970.patch
Type: text/x-patch
Size: 1169 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210722/87b9d19e/attachment-0001.bin>


More information about the cfe-commits mailing list