Skip to content

Optimize SREM/ZREM/HDEL to pause auto shrink when deleting multiple items#3144

Merged
enjoy-binbin merged 5 commits into
valkey-io:unstablefrom
enjoy-binbin:pause_resize
Feb 3, 2026
Merged

Optimize SREM/ZREM/HDEL to pause auto shrink when deleting multiple items#3144
enjoy-binbin merged 5 commits into
valkey-io:unstablefrom
enjoy-binbin:pause_resize

Conversation

@enjoy-binbin

@enjoy-binbin enjoy-binbin commented Feb 1, 2026

Copy link
Copy Markdown
Member

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.

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>
Comment thread src/t_zset.c Outdated
@enjoy-binbin enjoy-binbin added the run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) label Feb 1, 2026
@codecov

codecov Bot commented Feb 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.87%. Comparing base (851eaaf) to head (5d74a8f).
⚠️ Report is 7 commits behind head on unstable.

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     
Files with missing lines Coverage Δ
src/t_hash.c 95.47% <100.00%> (+0.08%) ⬆️
src/t_set.c 97.71% <100.00%> (-0.34%) ⬇️
src/t_zset.c 97.07% <100.00%> (+0.04%) ⬆️

... and 18 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot removed the run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) label Feb 1, 2026

@dvkashapov dvkashapov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, clean and simple

Comment thread src/t_zset.c Outdated
Co-authored-by: Daniil Kashapov <daniil.kashapov.ykt@gmail.com>
Signed-off-by: Binbin <binloveplay1314@qq.com>
Comment thread src/t_set.c Outdated
Signed-off-by: Binbin <binloveplay1314@qq.com>
Signed-off-by: Binbin <binloveplay1314@qq.com>
Signed-off-by: Binbin <binloveplay1314@qq.com>
@enjoy-binbin enjoy-binbin changed the title Pause auto shrink in ZREM and SREM commands Pause auto shrink in ZREM / SREM / HDEL commands Feb 3, 2026

@zuiderkwast zuiderkwast left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is better, without behavior change.

For release notes, we can say something like "optimize srem/zrem/hdel when deleting multiple items".

@enjoy-binbin enjoy-binbin changed the title Pause auto shrink in ZREM / SREM / HDEL commands Optimize SREM/ZREM/HDEL to pause auto shrink when deleting multiple items Feb 3, 2026
@enjoy-binbin enjoy-binbin merged commit 8ed270f into valkey-io:unstable Feb 3, 2026
24 checks passed
@enjoy-binbin enjoy-binbin deleted the pause_resize branch February 3, 2026 16:15
@zuiderkwast zuiderkwast added the release-notes This issue should get a line item in the release notes label Feb 3, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes This issue should get a line item in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants