From e38537202e77ab9ead1eaa5ef91f9d0739e7235a Mon Sep 17 00:00:00 2001 From: John Sully Date: Tue, 17 May 2022 03:30:21 +0000 Subject: [PATCH] Avoid unnecessary rehashing when a rehash is abandoned --- src/dict.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/dict.cpp b/src/dict.cpp index 9a15830ae..e8de025f7 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -447,6 +447,9 @@ LDone: } void dictRehashAsync(dictAsyncRehashCtl *ctl) { + if (ctl->abondon.load(std::memory_order_acquire)) { + ctl->hashIdx = ctl->queue.size(); + } for (size_t idx = ctl->hashIdx; idx < ctl->queue.size(); ++idx) { auto &wi = ctl->queue[idx]; wi.hash = dictHashKey(ctl->dict, dictGetKey(wi.de)); @@ -456,6 +459,9 @@ void dictRehashAsync(dictAsyncRehashCtl *ctl) { } bool dictRehashSomeAsync(dictAsyncRehashCtl *ctl, size_t hashes) { + if (ctl->abondon.load(std::memory_order_acquire)) { + ctl->hashIdx = ctl->queue.size(); + } size_t max = std::min(ctl->hashIdx + hashes, ctl->queue.size()); for (; ctl->hashIdx < max; ++ctl->hashIdx) { auto &wi = ctl->queue[ctl->hashIdx];