Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Unified Diff: Source/wtf/HashTable.h

Issue 17583004: Improve WTF::HashTable performance by changing probing method (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: rebaseline named-grid-line-get-set which depends on hashtable iteration order Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/css-grid-layout/named-grid-line-get-set-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/HashTable.h
diff --git a/Source/wtf/HashTable.h b/Source/wtf/HashTable.h
index e99bc1e9cdccd0232083343cba1855cad9eb97f7..5e3751dacc449fa7146d1207c955b7745e2723ed 100644
--- a/Source/wtf/HashTable.h
+++ b/Source/wtf/HashTable.h
@@ -485,6 +485,7 @@ namespace WTF {
static const int m_maxLoad = 2;
static const int m_minLoad = 6;
+ static const int perturbShift = 5;
ValueType* m_table;
int m_tableSize;
@@ -561,16 +562,6 @@ namespace WTF {
{
}
- inline unsigned doubleHash(unsigned key)
- {
- key = ~key + (key >> 23);
- key ^= (key << 12);
- key ^= (key >> 7);
- key ^= (key << 2);
- key ^= (key >> 20);
- return key;
- }
-
#if ASSERT_DISABLED
template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
@@ -603,11 +594,11 @@ namespace WTF {
{
checkKey<HashTranslator>(key);
- int k = 0;
int sizeMask = m_tableSizeMask;
ValueType* table = m_table;
unsigned h = HashTranslator::hash(key);
- int i = h & sizeMask;
+ unsigned i = h;
+ unsigned perturb = h;
if (!table)
return 0;
@@ -623,7 +614,7 @@ namespace WTF {
#endif
while (1) {
- ValueType* entry = table + i;
+ ValueType* entry = table + (i & sizeMask);
// we count on the compiler to optimize out this branch
if (HashFunctions::safeToCompareToEmptyOrDeleted) {
@@ -649,9 +640,8 @@ namespace WTF {
m_stats->recordCollisionAtCount(perTableProbeCount);
#endif
- if (k == 0)
- k = 1 | doubleHash(h);
- i = (i + k) & sizeMask;
+ perturb >>= perturbShift;
+ i = i*5 + perturb + 1;
}
}
@@ -662,11 +652,11 @@ namespace WTF {
ASSERT(m_table);
checkKey<HashTranslator>(key);
- int k = 0;
ValueType* table = m_table;
int sizeMask = m_tableSizeMask;
unsigned h = HashTranslator::hash(key);
- int i = h & sizeMask;
+ unsigned i = h;
+ unsigned perturb = h;
#if DUMP_HASHTABLE_STATS
atomicIncrement(&HashTableStats::numAccesses);
@@ -681,7 +671,7 @@ namespace WTF {
ValueType* deletedEntry = 0;
while (1) {
- ValueType* entry = table + i;
+ ValueType* entry = table + (i & sizeMask);
// we count on the compiler to optimize out this branch
if (HashFunctions::safeToCompareToEmptyOrDeleted) {
@@ -712,9 +702,8 @@ namespace WTF {
m_stats->recordCollisionAtCount(perTableProbeCount);
#endif
- if (k == 0)
- k = 1 | doubleHash(h);
- i = (i + k) & sizeMask;
+ perturb >>= perturbShift;
+ i = i*5 + perturb + 1;
}
}
@@ -725,11 +714,11 @@ namespace WTF {
ASSERT(m_table);
checkKey<HashTranslator>(key);
- int k = 0;
ValueType* table = m_table;
int sizeMask = m_tableSizeMask;
unsigned h = HashTranslator::hash(key);
- int i = h & sizeMask;
+ unsigned i = h;
+ unsigned perturb = h;
#if DUMP_HASHTABLE_STATS
atomicIncrement(&HashTableStats::numAccesses);
@@ -744,7 +733,7 @@ namespace WTF {
ValueType* deletedEntry = 0;
while (1) {
- ValueType* entry = table + i;
+ ValueType* entry = table + (i & sizeMask);
// we count on the compiler to optimize out this branch
if (HashFunctions::safeToCompareToEmptyOrDeleted) {
@@ -775,9 +764,8 @@ namespace WTF {
m_stats->recordCollisionAtCount(perTableProbeCount);
#endif
- if (k == 0)
- k = 1 | doubleHash(h);
- i = (i + k) & sizeMask;
+ perturb >>= perturbShift;
+ i = i*5 + perturb + 1;
}
}
@@ -821,11 +809,11 @@ namespace WTF {
ASSERT(m_table);
- int k = 0;
ValueType* table = m_table;
int sizeMask = m_tableSizeMask;
unsigned h = HashTranslator::hash(key);
- int i = h & sizeMask;
+ unsigned i = h;
+ unsigned perturb = h;
#if DUMP_HASHTABLE_STATS
atomicIncrement(&HashTableStats::numAccesses);
@@ -840,7 +828,7 @@ namespace WTF {
ValueType* deletedEntry = 0;
ValueType* entry;
while (1) {
- entry = table + i;
+ entry = table + (i & sizeMask);
// we count on the compiler to optimize out this branch
if (HashFunctions::safeToCompareToEmptyOrDeleted) {
@@ -871,9 +859,8 @@ namespace WTF {
m_stats->recordCollisionAtCount(perTableProbeCount);
#endif
- if (k == 0)
- k = 1 | doubleHash(h);
- i = (i + k) & sizeMask;
+ perturb >>= perturbShift;
+ i = i*5 + perturb + 1;
}
if (deletedEntry) {
« no previous file with comments | « LayoutTests/fast/css-grid-layout/named-grid-line-get-set-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698