From 4066ce8f3ae0161d2d5d6465379fe28ef95747c2 Mon Sep 17 00:00:00 2001 From: John Sully Date: Wed, 3 Mar 2021 07:05:12 +0000 Subject: [PATCH] Don't let dictionaries shrink too rapidly. It can cause massive perf issues while in the shrink rehash Former-commit-id: a7ad346e4f03c85d22a29c8268d35471e86283aa --- src/dict.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dict.cpp b/src/dict.cpp index 0bf7e6c36..1d0a0e266 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -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; }