[PATCH] D52016: [clangd] Don't create child AND and OR iterators with one posting list

Kirill Bobyrev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 13 00:48:40 PDT 2018


kbobyrev created this revision.
kbobyrev added reviewers: ioeric, ilya-biryukov, sammccall.
kbobyrev added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay.

`AND( AND( Child ) ... )` -> `AND( Child ... )`
`AND( OR( Child) ... )` -> `AND( Child ... )`

This simple optimization results in 5-6% performance improvement in the benchmark with 2000 serialized `FuzzyFindRequest`s.


https://reviews.llvm.org/D52016

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


Index: clang-tools-extra/clangd/index/dex/Dex.cpp
===================================================================
--- clang-tools-extra/clangd/index/dex/Dex.cpp
+++ clang-tools-extra/clangd/index/dex/Dex.cpp
@@ -144,8 +144,10 @@
     if (It != InvertedIndex.end())
       TrigramIterators.push_back(create(It->second));
   }
-  if (!TrigramIterators.empty())
+  if (TrigramIterators.size() > 1)
     TopLevelChildren.push_back(createAnd(move(TrigramIterators)));
+  else if (TrigramIterators.size() == 1)
+    TopLevelChildren.push_back(move(TrigramIterators.front()));
 
   // Generate scope tokens for search query.
   std::vector<std::unique_ptr<Iterator>> ScopeIterators;
@@ -155,8 +157,10 @@
       ScopeIterators.push_back(create(It->second));
   }
   // Add OR iterator for scopes if there are any Scope Iterators.
-  if (!ScopeIterators.empty())
+  if (ScopeIterators.size() > 1)
     TopLevelChildren.push_back(createOr(move(ScopeIterators)));
+  else if (ScopeIterators.size() == 1)
+    TopLevelChildren.push_back(move(ScopeIterators.front()));
 
   // Add proximity paths boosting.
   auto BoostingIterators = createFileProximityIterators(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52016.165212.patch
Type: text/x-patch
Size: 1156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180913/a6db40a4/attachment.bin>


More information about the cfe-commits mailing list