Skip to content

Commit cad97a4

Browse files
committed
Restore FNV hash.
Rotating hash is known for collisions and we do have a problem with collisions on some scenarios here. Now, that we have stronger hash, PropertyMap does not need prime size policy.
1 parent 944120b commit cad97a4

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

lib/Common/DataStructures/Comparer.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct DefaultComparer<size_t>
6868
#ifdef TARGET_64
6969
// For 64 bits we want all 64 bits of the pointer to be represented in the hash code.
7070
uint32 hi = ((UINT_PTR) i >> 32);
71-
uint32 lo = (uint32) (i & 0xFFFFFFFF);
71+
uint32 lo = (uint32)i;
7272
hash_t hash = hi ^ lo;
7373
#else
7474
hash_t hash = i;
@@ -112,19 +112,15 @@ struct RecyclerPointerComparer
112112
}
113113
};
114114

115-
// FNV-1a hash -> https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
116-
// #define CC_HASH_OFFSET_VALUE 2166136261
117-
// #define CC_HASH_LOGIC(hash, byte) \
118-
// hash ^= byte; \
119-
// hash *= 16777619
120-
121-
// previous hash function.
122-
// TODO: hash function below is bad for key distribution.
123-
// FNV-1a above results better but expensive for lookups in small data sets.
124-
#define CC_HASH_OFFSET_VALUE 0
125-
#define CC_HASH_LOGIC(hash, byte) \
126-
hash = _rotl(hash, 7); \
127-
hash ^= byte;
115+
// TODO: FNV is a proven hash especially for short strings, which is common case here.
116+
// Still. it may be worth to consider a more recent block-based hash.
117+
// They tend to be faster, but it need to be examined against typical workloads.
118+
//
119+
// FNV-1a hash -> https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
120+
#define CC_HASH_OFFSET_VALUE 2166136261
121+
#define CC_HASH_LOGIC(hash, byte) \
122+
hash ^= byte; \
123+
hash *= 16777619
128124

129125
template <>
130126
struct DefaultComparer<GUID>

lib/Runtime/Base/ThreadContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ class ThreadContext sealed :
461461
};
462462

463463
public:
464-
typedef JsUtil::BaseHashSet<const Js::PropertyRecord *, HeapAllocator, PrimeSizePolicy, const Js::PropertyRecord *,
464+
typedef JsUtil::BaseHashSet<const Js::PropertyRecord *, HeapAllocator, PowerOf2SizePolicy, const Js::PropertyRecord *,
465465
Js::PropertyRecordStringHashComparer, JsUtil::SimpleHashedEntry, JsUtil::AsymetricResizeLock> PropertyMap;
466466
PropertyMap * propertyMap;
467467

0 commit comments

Comments
 (0)