Skip to content

ring/buffered: replace linked-list ring with slice-based circular buffer#146

Merged
cicoyle merged 4 commits intodapr:mainfrom
JoshVanL:ring-buffered-perf
Mar 16, 2026
Merged

ring/buffered: replace linked-list ring with slice-based circular buffer#146
cicoyle merged 4 commits intodapr:mainfrom
JoshVanL:ring-buffered-perf

Conversation

@JoshVanL
Copy link
Contributor

@JoshVanL JoshVanL commented Mar 9, 2026

Use a slice-based circular buffer instead of container/ring, adding dynamic growing (double on full) and shrinking (halve at 1/4 capacity). Track minCap so the buffer never shrinks below its initial allocation. Update tests for the new internals and add coverage for shrink, wraparound, and edge cases.

Copilot AI review requested due to automatic review settings March 9, 2026 16:55
@JoshVanL JoshVanL requested review from a team as code owners March 9, 2026 16:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR replaces the linked-list-based (container/ring) circular buffer implementation of Buffered in the ring package with a slice-based circular buffer. The new implementation uses doubling on growth and halving at 1/4 capacity for shrinking, and tracks minCap so the buffer never shrinks below its initial allocation. Tests are updated to match the new internals and new test cases are added for shrink behavior, wraparound correctness, and edge cases.

Changes:

  • Replaced the Ring-backed struct fields with a slice (buf), head index, count, and minCap, implementing grow() and shrink() methods that linearize the circular contents into a new allocation.
  • Updated all existing tests to assert against the new internal representation (len(b.buf) and b.Len()) and added three new test functions covering shrink-below-minCap, empty-front, and wraparound scenarios.
  • Cleaned up the NewBuffered docstring (removed joke) and updated all method docstrings to reflect the new implementation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
ring/buffered.go Replaced linked-list ring with slice-based circular buffer; added grow/shrink methods; bufferSize parameter is now unused.
ring/buffered_test.go Updated existing tests for new internals; added tests for shrink-below-minCap, empty-front, and wraparound edge cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Use a slice-based circular buffer instead of container/ring, adding
dynamic growing (double on full) and shrinking (halve at 1/4 capacity).
Track minCap so the buffer never shrinks below its initial allocation.
Update tests for the new internals and add coverage for shrink,
wraparound, and edge cases.

Signed-off-by: joshvanl <me@joshvanl.dev>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

acroca
acroca previously approved these changes Mar 10, 2026
Copy link
Contributor

@cicoyle cicoyle left a comment

Choose a reason for hiding this comment

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

few things from me!

Signed-off-by: joshvanl <me@joshvanl.dev>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

JoshVanL and others added 2 commits March 11, 2026 14:22
Signed-off-by: joshvanl <me@joshvanl.dev>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Josh van Leeuwen <me@joshvanl.dev>
@cicoyle cicoyle merged commit af26c70 into dapr:main Mar 16, 2026
6 checks passed
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.

4 participants