Skip to content

Commit 1390675

Browse files
committed
[SpecialCaseList] Remove TrigramIndex
`TrigramIndex` was added back in https://reviews.llvm.org/D27188 as an optimization to make `SpecialCaseList::match()` faster. I've found that `TrigramIndex` actually makes the function slower and it has no functional use, so we can remove it. I grabbed the list of queries passed to `SpecialCaseList::match()` on a random very large file (`AArch64ISelLowering.cpp`) and measured the runtime to call `match()` on all of them with [this line](https://github.com/llvm/llvm-project/blob/8e1f820bb4eadf5c0704818f6063e0db1006e32d/llvm/lib/Support/SpecialCaseList.cpp#L64) disabled and then enabled. ``` $ hyperfine --warmup 3 'GTEST_FILTER="SpecialCaseListTest.Large" USE_TRIGRAMS=1 build/unittests/Support/SupportTests' 'GTEST_FILTER="SpecialCaseListTest.Large" USE_TRIGRAMS=0 build/unittests/Support/SupportTests' Benchmark 1: GTEST_FILTER="SpecialCaseListTest.Large" USE_TRIGRAMS=1 build/unittests/Support/SupportTests Time (mean ± σ): 575.9 ms ± 20.3 ms [User: 573.1 ms, System: 2.7 ms] Range (min … max): 555.5 ms … 620.0 ms 10 runs Benchmark 2: GTEST_FILTER="SpecialCaseListTest.Large" USE_TRIGRAMS=0 build/unittests/Support/SupportTests Time (mean ± σ): 283.4 ms ± 6.7 ms [User: 280.3 ms, System: 3.0 ms] Range (min … max): 277.0 ms … 294.9 ms 10 runs Summary 'GTEST_FILTER="SpecialCaseListTest.Large" USE_TRIGRAMS=0 build/unittests/Support/SupportTests' ran 2.03 ± 0.09 times faster than 'GTEST_FILTER="SpecialCaseListTest.Large" USE_TRIGRAMS=1 build/unittests/Support/SupportTests' ``` Using `perf` I found that most of the runtime in `TrigramIndex::isDefinitelyOut()` comes from a division operation that seems to come from `std::unordered_map`: https://github.com/llvm/llvm-project/blob/8e1f820bb4eadf5c0704818f6063e0db1006e32d/llvm/include/llvm/Support/TrigramIndex.h#L62 Removing `TrigramIndex` will make it easier to potentially switch to using `GlobPattern` instead of a full regex for `SpecialCaseList`. See discussion in https://reviews.llvm.org/D152762 for details. Reviewed By: MaskRay, #sanitizers, vitalybuka Differential Revision: https://reviews.llvm.org/D153171
1 parent d565980 commit 1390675

File tree

9 files changed

+1
-316
lines changed

9 files changed

+1
-316
lines changed

llvm/include/llvm/Support/SpecialCaseList.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454

5555
#include "llvm/ADT/StringMap.h"
5656
#include "llvm/Support/Regex.h"
57-
#include "llvm/Support/TrigramIndex.h"
5857
#include <memory>
5958
#include <string>
6059
#include <vector>
@@ -128,7 +127,6 @@ class SpecialCaseList {
128127

129128
private:
130129
StringMap<unsigned> Strings;
131-
TrigramIndex Trigrams;
132130
std::vector<std::pair<std::unique_ptr<Regex>, unsigned>> RegExes;
133131
};
134132

@@ -155,5 +153,4 @@ class SpecialCaseList {
155153

156154
} // namespace llvm
157155

158-
#endif // LLVM_SUPPORT_SPECIALCASELIST_H
159-
156+
#endif // LLVM_SUPPORT_SPECIALCASELIST_H

llvm/include/llvm/Support/TrigramIndex.h

Lines changed: 0 additions & 67 deletions
This file was deleted.

llvm/lib/Support/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ add_llvm_component_library(LLVMSupport
226226
TimeProfiler.cpp
227227
Timer.cpp
228228
ToolOutputFile.cpp
229-
TrigramIndex.cpp
230229
Twine.cpp
231230
TypeSize.cpp
232231
Unicode.cpp

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ bool SpecialCaseList::Matcher::insert(std::string Regexp,
3737
Strings[Regexp] = LineNumber;
3838
return true;
3939
}
40-
Trigrams.insert(Regexp);
4140

4241
// Replace * with .*
4342
for (size_t pos = 0; (pos = Regexp.find('*', pos)) != std::string::npos;
@@ -61,8 +60,6 @@ unsigned SpecialCaseList::Matcher::match(StringRef Query) const {
6160
auto It = Strings.find(Query);
6261
if (It != Strings.end())
6362
return It->second;
64-
if (Trigrams.isDefinitelyOut(Query))
65-
return false;
6663
for (const auto &RegExKV : RegExes)
6764
if (RegExKV.first->match(Query))
6865
return RegExKV.second;

llvm/lib/Support/TrigramIndex.cpp

Lines changed: 0 additions & 107 deletions
This file was deleted.

llvm/unittests/Support/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ add_llvm_unittest(SupportTests
8989
TypeSizeTest.cpp
9090
TypeTraitsTest.cpp
9191
TrailingObjectsTest.cpp
92-
TrigramIndexTest.cpp
9392
UnicodeTest.cpp
9493
VersionTupleTest.cpp
9594
VirtualFileSystemTest.cpp

llvm/unittests/Support/TrigramIndexTest.cpp

Lines changed: 0 additions & 131 deletions
This file was deleted.

llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ static_library("Support") {
141141
"TimeProfiler.cpp",
142142
"Timer.cpp",
143143
"ToolOutputFile.cpp",
144-
"TrigramIndex.cpp",
145144
"Twine.cpp",
146145
"TypeSize.cpp",
147146
"Unicode.cpp",

llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ unittest("SupportTests") {
8989
"TimerTest.cpp",
9090
"ToolOutputFileTest.cpp",
9191
"TrailingObjectsTest.cpp",
92-
"TrigramIndexTest.cpp",
9392
"TypeNameTest.cpp",
9493
"TypeSizeTest.cpp",
9594
"TypeTraitsTest.cpp",

0 commit comments

Comments
 (0)