[PATCH] D137601: Only hash the start of keys in StringMap

Jamie Hill-Daniel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 7 17:04:34 PST 2022


clubby789 created this revision.
clubby789 added a reviewer: chandlerc.
Herald added a subscriber: hiraditya.
Herald added a project: All.
clubby789 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Hashing large constant blobs results in long compile times - hash only up to 1024 bytes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137601

Files:
  llvm/lib/Support/StringMap.cpp


Index: llvm/lib/Support/StringMap.cpp
===================================================================
--- llvm/lib/Support/StringMap.cpp
+++ llvm/lib/Support/StringMap.cpp
@@ -84,7 +84,7 @@
   // Hash table unallocated so far?
   if (NumBuckets == 0)
     init(16);
-  unsigned FullHashValue = djbHash(Name, 0);
+  unsigned FullHashValue = djbHash(Name.take_front(1024), 0);
   unsigned BucketNo = FullHashValue & (NumBuckets - 1);
   unsigned *HashTable = getHashTable(TheTable, NumBuckets);
 
@@ -139,7 +139,8 @@
 int StringMapImpl::FindKey(StringRef Key) const {
   if (NumBuckets == 0)
     return -1; // Really empty table?
-  unsigned FullHashValue = djbHash(Key, 0);
+
+  unsigned FullHashValue = djbHash(Key.take_front(1024), 0);
   unsigned BucketNo = FullHashValue & (NumBuckets - 1);
   unsigned *HashTable = getHashTable(TheTable, NumBuckets);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137601.473831.patch
Type: text/x-patch
Size: 862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221108/27e8480a/attachment.bin>


More information about the llvm-commits mailing list