Optimize SREM/ZREM/HDEL to pause auto shrink when deleting multiple items#3144
Merged
Conversation
When ZREM and SREM delete a large number of elements, we can apply the same optimization as ZREMRANGEBY*, which is to temporarily pause the autoshrink of the corresponding hashtable to avoid triggering resize/rehash repeatedly during the deletion process. This theoretically leads to some performance improvements. Furthermore, by only triggering a resize once at the end (i.e., only when `hashtableResumeAutoShrink` is called), we can get the most right resize, preventing further resizes during the resize/rehash process. Signed-off-by: Binbin <binloveplay1314@qq.com>
enjoy-binbin
commented
Feb 1, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #3144 +/- ##
============================================
+ Coverage 74.85% 74.87% +0.02%
============================================
Files 129 129
Lines 71210 71215 +5
============================================
+ Hits 53302 53322 +20
+ Misses 17908 17893 -15
🚀 New features to boost your workflow:
|
dvkashapov
approved these changes
Feb 2, 2026
dvkashapov
left a comment
Member
There was a problem hiding this comment.
Overall LGTM, clean and simple
Co-authored-by: Daniil Kashapov <daniil.kashapov.ykt@gmail.com> Signed-off-by: Binbin <binloveplay1314@qq.com>
zuiderkwast
reviewed
Feb 2, 2026
Signed-off-by: Binbin <binloveplay1314@qq.com>
Signed-off-by: Binbin <binloveplay1314@qq.com>
Signed-off-by: Binbin <binloveplay1314@qq.com>
zuiderkwast
approved these changes
Feb 3, 2026
zuiderkwast
left a comment
Contributor
There was a problem hiding this comment.
Yes, this is better, without behavior change.
For release notes, we can say something like "optimize srem/zrem/hdel when deleting multiple items".
sundb
added a commit
to redis/redis
that referenced
this pull request
Feb 14, 2026
The idea comes directly from ValKey: valkey-io/valkey#3144 Deleting many fields from a hash/zset/set stored as a dict can trigger repeated shrink/rehash work during the loop. --------- Co-authored-by: Binbin <binloveplay1314@qq.com> Co-authored-by: debing.sun <debing.sun@redis.com>
harrylin98
pushed a commit
to harrylin98/valkey_forked
that referenced
this pull request
Feb 19, 2026
…tems (valkey-io#3144) When ZREM / SREM / HDEL delete a large number of elements, we can apply the same optimization as ZREMRANGEBY*, which is to temporarily pause the autoshrink of the corresponding hashtable to avoid triggering resize/rehash repeatedly during the deletion process. This theoretically leads to some performance improvements. Furthermore, by only triggering a resize once at the end (i.e., only when `hashtableResumeAutoShrink` is called), we can get the most right resize, preventing further resizes during the resize/rehash process. Signed-off-by: Binbin <binloveplay1314@qq.com>
hpatro
pushed a commit
to hpatro/valkey
that referenced
this pull request
Mar 5, 2026
…tems (valkey-io#3144) When ZREM / SREM / HDEL delete a large number of elements, we can apply the same optimization as ZREMRANGEBY*, which is to temporarily pause the autoshrink of the corresponding hashtable to avoid triggering resize/rehash repeatedly during the deletion process. This theoretically leads to some performance improvements. Furthermore, by only triggering a resize once at the end (i.e., only when `hashtableResumeAutoShrink` is called), we can get the most right resize, preventing further resizes during the resize/rehash process. Signed-off-by: Binbin <binloveplay1314@qq.com> Signed-off-by: Harkrishn Patro <bunty.hari@gmail.com>
enjoy-binbin
pushed a commit
that referenced
this pull request
Apr 23, 2026
…3535) Match HGETDEL with the existing batch-delete pattern used by HDEL. HDEL already pauses hashtable auto-shrink while deleting multiple fields so shrink evaluation is deferred until the batch completes. HGETDEL was missing the same optimization even though it also deletes fields in a loop. Pause auto-shrink for hashtable-encoded hashes before the HGETDEL delete loop and resume it once afterwards. This preserves observable behavior and reduces redundant shrink work for multi-field deletes. Same as #3144. Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
sarthakaggarwal97
pushed a commit
to sarthakaggarwal97/valkey
that referenced
this pull request
Apr 23, 2026
…alkey-io#3535) Match HGETDEL with the existing batch-delete pattern used by HDEL. HDEL already pauses hashtable auto-shrink while deleting multiple fields so shrink evaluation is deferred until the batch completes. HGETDEL was missing the same optimization even though it also deletes fields in a loop. Pause auto-shrink for hashtable-encoded hashes before the HGETDEL delete loop and resume it once afterwards. This preserves observable behavior and reduces redundant shrink work for multi-field deletes. Same as valkey-io#3144. Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
madolson
pushed a commit
that referenced
this pull request
Apr 27, 2026
…3535) Match HGETDEL with the existing batch-delete pattern used by HDEL. HDEL already pauses hashtable auto-shrink while deleting multiple fields so shrink evaluation is deferred until the batch completes. HGETDEL was missing the same optimization even though it also deletes fields in a loop. Pause auto-shrink for hashtable-encoded hashes before the HGETDEL delete loop and resume it once afterwards. This preserves observable behavior and reduces redundant shrink work for multi-field deletes. Same as #3144. Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When ZREM / SREM / HDEL delete a large number of elements, we can apply the same
optimization as ZREMRANGEBY*, which is to temporarily pause the autoshrink of
the corresponding hashtable to avoid triggering resize/rehash repeatedly during
the deletion process.
This theoretically leads to some performance improvements. Furthermore, by only
triggering a resize once at the end (i.e., only when
hashtableResumeAutoShrinkis called), we can get the most right resize, preventing further resizes during
the resize/rehash process.