Skip to content

Avoid memory allocation on quicklist iteration#14720

Merged
skaslev merged 2 commits intoredis:unstablefrom
skaslev:ql-iter-no-alloc
Jan 21, 2026
Merged

Avoid memory allocation on quicklist iteration#14720
skaslev merged 2 commits intoredis:unstablefrom
skaslev:ql-iter-no-alloc

Conversation

@skaslev
Copy link
Collaborator

@skaslev skaslev commented Jan 20, 2026

This change is the last in the series (see #14200 and #14473) where we store iterators
on the stack rather than allocating them the heap.


Note

Shifts quicklist iteration to a stack-based API to avoid per-iteration heap allocations.

  • Replace quicklistGetIterator* with quicklistInitIterator* and quicklistReleaseIterator with quicklistResetIterator; quicklistInitIteratorAtIdx()/quicklistInitIteratorEntryAtIdx() now return 1/0 instead of pointers
  • Update all call sites in quicklist.c tests/benchmarks, t_list.c, and server.h (listTypeIterator now embeds quicklistIter instead of a pointer)
  • Minor comment/wording tweaks and related iterator usage adjustments (e.g., quicklistNext assumes a valid iterator)

Written by Cursor Bugbot for commit ea17980. This will update automatically on new commits. Configure here.

@skaslev skaslev requested a review from sundb January 20, 2026 15:25
@augmentcode
Copy link

augmentcode bot commented Jan 20, 2026

🤖 Augment PR Summary

Summary: This PR removes heap allocation from quicklist iteration by switching to stack-allocated iterators throughout the quicklist API.

Changes:

  • Replaced quicklistGetIterator* functions with quicklistInitIterator* initializers that fill a caller-provided quicklistIter.
  • Replaced quicklistReleaseIterator() with quicklistResetIterator(), which finalizes the iterator by recompressing the current node (no free).
  • Updated iterator-at-index helpers to return success/failure (int) instead of a nullable pointer.
  • Converted Redis list-type iteration (listTypeIterator) to embed quicklistIter directly, avoiding per-iterator allocations.
  • Adjusted quicklist tests and list command helpers to use the new stack-based iterator lifecycle.

Technical Notes: The iterator “cleanup” path still recompresses the current node to preserve quicklist compression semantics, but no longer performs allocator work for iterator creation/destruction.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 1 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

@skaslev skaslev requested a review from moticless January 20, 2026 21:23
Copy link
Collaborator

@sundb sundb left a comment

Choose a reason for hiding this comment

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

LGTM

@skaslev skaslev merged commit 818046d into redis:unstable Jan 21, 2026
18 checks passed
fcostaoliveira pushed a commit to filipecosta90/redis that referenced this pull request Jan 21, 2026
This change is the last in the series (see redis#14200 and redis#14473) where we
store iterators
on the stack rather than allocating them the heap.
@skaslev skaslev deleted the ql-iter-no-alloc branch January 21, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants