Skip to content

Commit 944f30a

Browse files
committed
Use Fibonacci hash to reduce TinyDictionary keys to buckets
1 parent d9f0e4b commit 944f30a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/Runtime/Types/TypePath.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ namespace Js
2626

2727
uint32 ReduceKeyToIndex(PropertyId key)
2828
{
29-
// we use 4-bit bucket index
30-
// sometimes we have keys that differ in higher bits, so smudge the bits down a little
31-
// to reduce the possibility of collisions
32-
key ^= (uint)key >> 15;
33-
key ^= (uint)key >> 7;
34-
return key & (PowerOf2_BUCKETS - 1);
29+
// we use 4-bit bucket index, but we often have keys that are larger.
30+
// use Fibonacci hash to reduce the possibility of collisions
31+
#if TARGET_64
32+
return (key * 11400714819323198485llu) >> 60;
33+
#else
34+
return (key * 2654435769ul) >> 28;
35+
#endif
3536
}
3637

3738
void Add(PropertyId key, byte value)
@@ -50,7 +51,7 @@ namespace Js
5051
else
5152
{
5253
buckets[bucketIndex] = value;
53-
next[value & 127] = i;
54+
next[value] = i;
5455
}
5556
}
5657

0 commit comments

Comments
 (0)