[llvm] [DebugNames] Use hashes to quickly filter false positives (PR #79755)

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 28 07:36:11 PST 2024


https://github.com/felipepiovezan created https://github.com/llvm/llvm-project/pull/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)

>From 53fa160444ec97577bbea0ce0c99a28d6504173d Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
Date: Sun, 28 Jan 2024 07:23:49 -0800
Subject: [PATCH] [DebugNames] Use hashes to quickly filter false positives

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)
---
 llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
index 03ad5d133caddf4..a1a1ac093aa5c12 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
@@ -937,9 +937,11 @@ DWARFDebugNames::ValueIterator::findEntryOffsetInCurrentIndex() {
     return std::nullopt; // Empty bucket
 
   for (; Index <= Hdr.NameCount; ++Index) {
-    uint32_t Hash = CurrentIndex->getHashArrayEntry(Index);
-    if (Hash % Hdr.BucketCount != Bucket)
+    uint32_t HashAtIndex = CurrentIndex->getHashArrayEntry(Index);
+    if (HashAtIndex % Hdr.BucketCount != Bucket)
       return std::nullopt; // End of bucket
+    if (HashAtIndex != Hash)
+      continue;
 
     NameTableEntry NTE = CurrentIndex->getNameTableEntry(Index);
     if (NTE.getString() == Key)



More information about the llvm-commits mailing list