Skip to content

Conversation

@vitalybuka
Copy link
Collaborator

@vitalybuka vitalybuka commented Oct 22, 2025

The RadixTree key order was Prefix then Suffix. This commit changes the
order to Suffix then Prefix. Assuming that, especially in case of
"src:", suffixes are often more diverse than prefixes. So filtering by
suffix first should be more efficient.

No noticeable improvement on benchmarks:

https://gist.github.com/vitalybuka/d6d394071a4d540a50a119f317bd4e5a

Created using spr 1.3.7
@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2025

@llvm/pr-subscribers-llvm-support

Author: Vitaly Buka (vitalybuka)

Changes

The RadixTree key order was Prefix then Suffix. This commit changes the
order to Suffix then Prefix. Assuming that, especially in case of
"src:", suffixes are often more diverse than prefixes. So filtering by
suffix first should be more efficient.


Full diff: https://github.com/llvm/llvm-project/pull/164544.diff

2 Files Affected:

  • (modified) llvm/include/llvm/Support/SpecialCaseList.h (+3-3)
  • (modified) llvm/lib/Support/SpecialCaseList.cpp (+6-5)
diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h
index 471f8e779fa24..c077f8857c9c8 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -166,10 +166,10 @@ class SpecialCaseList {
 
     std::vector<GlobMatcher::Glob> Globs;
 
-    RadixTree<iterator_range<StringRef::const_iterator>,
-              RadixTree<iterator_range<StringRef::const_reverse_iterator>,
+    RadixTree<iterator_range<StringRef::const_reverse_iterator>,
+              RadixTree<iterator_range<StringRef::const_iterator>,
                         SmallVector<const GlobMatcher::Glob *, 1>>>
-        PrefixSuffixToGlob;
+        SuffixPrefixToGlob;
   };
 
   /// Represents a set of patterns and their line numbers
diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp
index 9bd1c199695d1..15367afd91e72 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -94,8 +94,8 @@ void SpecialCaseList::GlobMatcher::preprocess(bool BySize) {
     StringRef Prefix = G.Pattern.prefix();
     StringRef Suffix = G.Pattern.suffix();
 
-    auto &SToGlob = PrefixSuffixToGlob.emplace(Prefix).first->second;
-    auto &V = SToGlob.emplace(reverse(Suffix)).first->second;
+    auto &PToGlob = SuffixPrefixToGlob.emplace(reverse(Suffix)).first->second;
+    auto &V = PToGlob.emplace(Prefix).first->second;
     V.emplace_back(&G);
   }
 }
@@ -103,9 +103,10 @@ void SpecialCaseList::GlobMatcher::preprocess(bool BySize) {
 void SpecialCaseList::GlobMatcher::match(
     StringRef Query,
     llvm::function_ref<void(StringRef Rule, unsigned LineNo)> Cb) const {
-  if (!PrefixSuffixToGlob.empty()) {
-    for (const auto &[_, SToGlob] : PrefixSuffixToGlob.find_prefixes(Query)) {
-      for (const auto &[_, V] : SToGlob.find_prefixes(reverse(Query))) {
+  if (!SuffixPrefixToGlob.empty()) {
+    for (const auto &[_, PToGlob] :
+         SuffixPrefixToGlob.find_prefixes(reverse(Query))) {
+      for (const auto &[_, V] : PToGlob.find_prefixes(Query)) {
         for (const auto *G : reverse(V)) {
           if (G->Pattern.match(Query)) {
             Cb(G->Name, G->LineNo);

@vitalybuka vitalybuka marked this pull request as draft October 22, 2025 05:29
Created using spr 1.3.7
Created using spr 1.3.7
Created using spr 1.3.7
Created using spr 1.3.7
Created using spr 1.3.7
Created using spr 1.3.7
Created using spr 1.3.7
Created using spr 1.3.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants