Skip to content

Commit 4227645

Browse files
committed
[Runtime] Improve the metadata hashing function.
The inputs to the hash function is pointers that have a predictable patten. The hashes that we were generating and using for the metadata caches were not very good, and as a result we generated very deep search trees. A small change that improved the utilization of the 'length' field and another bit-rotate round improved the quality of the hash function. I am going to attach to the github commit two pictures. The first picture is the binary with the old hash. The first tree is very deep and sparse. The second picture is with the new hash function and the tree is very wide and uniform. I used the benchmark 'TypeFlood' in debug mode to generate huge amounts of metadata.
1 parent 866b44c commit 4227645

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

stdlib/public/runtime/MetadataCache.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,13 @@ class EntryRef {
6666
}
6767

6868
size_t hash() {
69-
size_t H = 0x56ba80d1 ^ length ;
69+
size_t H = 0x56ba80d1 * length ;
7070
for (unsigned i = 0; i < length; i++) {
7171
H = (H >> 10) | (H << ((sizeof(size_t) * 8) - 10));
7272
H ^= ((size_t)args[i]) ^ ((size_t)args[i] >> 19);
7373
}
74-
return H * 0x27d4eb2d;
74+
H *= 0x27d4eb2d;
75+
return (H >> 10) | (H << ((sizeof(size_t) * 8) - 10));
7576
}
7677

7778
const void * const *begin() const { return args; }

0 commit comments

Comments
 (0)