[clang-tools-extra] a0987e3 - [clangd] Improve performance of dex by 45-60%

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 23 06:29:01 PDT 2021


Author: Kirill Bobyrev
Date: 2021-07-23T15:28:35+02:00
New Revision: a0987e350ccce4fb9c3cbaf56732be1def5f810f

URL: https://github.com/llvm/llvm-project/commit/a0987e350ccce4fb9c3cbaf56732be1def5f810f
DIFF: https://github.com/llvm/llvm-project/commit/a0987e350ccce4fb9c3cbaf56732be1def5f810f.diff

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

Take full advantage of AND's iterator children size estimation: use early reset
in sync() and prevent large overhead. The idea is that the children at the
beginning of the list are smaller and cheaper to advance. Very large children
negate the effect of this performance optimisation and hence should be
advanced only when absolutely necessary. By reducing the number of large
iterators' updates, we increase the performance by a large margin.

This change was tested on a comprehensive query dataset. The performance
boost increases with the average length of the query, on small queries it is
close to 45% but the longer they go the closer it gets to 60% and beyond.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D106528

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/index/dex/Iterator.cpp b/clang-tools-extra/clangd/index/dex/Iterator.cpp
index 77e8175ca4b6..8b37403ff406 100644
--- a/clang-tools-extra/clangd/index/dex/Iterator.cpp
+++ b/clang-tools-extra/clangd/index/dex/Iterator.cpp
@@ -104,11 +104,19 @@ class AndIterator : public Iterator {
         // 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);


        


More information about the cfe-commits mailing list