diff --git a/clang-tools-extra/clangd/index/dex/Iterator.cpp b/clang-tools-extra/clangd/index/dex/Iterator.cpp --- a/clang-tools-extra/clangd/index/dex/Iterator.cpp +++ b/clang-tools-extra/clangd/index/dex/Iterator.cpp @@ -106,9 +106,13 @@ return; // 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(); + auto Candidate = Child->peek(); + if (Candidate > SyncID) { + SyncID = Candidate; NeedsAdvance = true; + // Reset and make sure advanceTo happens much less frequently on + // large posting lists. This accounts for 45-60% performance boost. + break; } } } while (NeedsAdvance);