Don't let dictionaries shrink too rapidly. It can cause massive perf issues while in the shrink rehash

Former-commit-id: a7ad346e4f03c85d22a29c8268d35471e86283aa
This commit is contained in:
John Sully 2021-03-03 07:05:12 +00:00
parent 76698beeaf
commit 4066ce8f3a

View File

@ -1267,6 +1267,7 @@ unsigned long dictScan(dict *d,
/* Expand the hash table if needed */
static int _dictExpandIfNeeded(dict *d)
{
static const size_t SHRINK_FACTOR = 4;
/* Incremental rehashing already in progress. Return. */
if (dictIsRehashing(d)) return DICT_OK;
@ -1283,10 +1284,10 @@ static int _dictExpandIfNeeded(dict *d)
{
return dictExpand(d, d->ht[0].used*2, false /*fShrink*/);
}
else if (d->ht[0].used > 0 && d->ht[0].used * 16 < d->ht[0].size && dict_can_resize)
else if (d->ht[0].used > 0 && d->ht[0].size >= (1024*SHRINK_FACTOR) && (d->ht[0].used * 16) < d->ht[0].size && dict_can_resize)
{
// If the dictionary has shurnk a lot we'll need to shrink the hash table instead
return dictExpand(d, d->ht[0].used*2, true /*fShrink*/);
return dictExpand(d, d->ht[0].size/SHRINK_FACTOR, true /*fShrink*/);
}
return DICT_OK;
}