Skip to content

Commit 69cb99f

Browse files
[DebugNames] Use hashes to quickly filter false positives (#79755)
The current implementation of DebugNames is _only_ using hashes to compute the bucket number. Once inside the bucket, it reverts back to string comparisons, even though not all hashes inside a bucket are identical. This commit changes the behavior so that we check the hash before comparing strings. Such check is so important that it speeds up a simple benchmark by 20%. In other words, the following expression evaluation time goes from 1100ms to 850ms. ``` bin/lldb \ --batch \ -o "b CodeGenFunction::GenerateCode" \ -o run \ -o "expr Fn" \ -- \ clang++ -c -g test.cpp -o /dev/null &> output ``` (Note, these numbers are considering the usage of IDX_parent)
1 parent d8e1b45 commit 69cb99f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,12 @@ DWARFDebugNames::ValueIterator::findEntryOffsetInCurrentIndex() {
937937
return std::nullopt; // Empty bucket
938938

939939
for (; Index <= Hdr.NameCount; ++Index) {
940-
uint32_t Hash = CurrentIndex->getHashArrayEntry(Index);
941-
if (Hash % Hdr.BucketCount != Bucket)
940+
uint32_t HashAtIndex = CurrentIndex->getHashArrayEntry(Index);
941+
if (HashAtIndex % Hdr.BucketCount != Bucket)
942942
return std::nullopt; // End of bucket
943+
// Only compare names if the hashes match.
944+
if (HashAtIndex != Hash)
945+
continue;
943946

944947
NameTableEntry NTE = CurrentIndex->getNameTableEntry(Index);
945948
if (NTE.getString() == Key)

0 commit comments

Comments
 (0)