Repository navigation
perf: avoid copying topology tokens - #237
Merged
Merged
Conversation
Greptile SummaryThis PR avoids copying and sorting token slices for every topology response by returning read-only slices from the current memberlist ring snapshot.
Confidence Score: 5/5The PR appears safe to merge with no concrete correctness, build, or security defects identified. Current topology consumers do not mutate returned token slices, memberlist snapshot replacement is covered under concurrent marshaling, and clients independently normalize token ordering before routing. Important Files Changed
Reviews (1): Last reviewed commit: "perf: avoid copying topology tokens" | Re-trigger Greptile |
perfloop
Bot
force-pushed
the
perfloop-pr-open-eyw0b53bz0
branch
from
August 22, 2026 06:39
934f1f4 to
fcc90fa
Compare
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
perfloop
Bot
force-pushed
the
perfloop-pr-open-eyw0b53bz0
branch
from
August 22, 2026 21:26
fcc90fa to
d71a405
Compare
ovaistariq
approved these changes
Aug 22, 2026
|
🎉 This PR is included in version 1.12.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
GetNodeTokensnow returns each normalized token slice from the current ring snapshot instead of allocating and sorting a copy for every topology response. Ring updates replace snapshots, and the current coordinator and protobuf response path only read the slices.The bufconn RPC benchmark covers 1, 3, and 16 active members at 128, 512, and 4096 tokens. The race regression marshals topology data while memberlist publishes replacements. This relies on snapshot replacement and read-only consumers; a mutating consumer or non-memberlist KV backend must copy the slice.
Verification
make install-protoc-plugins && PATH="$(go env GOPATH)/bin:$PATH" make test-coordinatormake install-protoc-plugins && PATH="$(go env GOPATH)/bin:$PATH" GOFLAGS=-race make test-coordinator TEST=TestGetNodeTokens_ResponseSlicesRemainStableDuringRingUpdatesWorkload:
CacheService.GetTopology RPC over bufconn with 1 active member and 512 tokens per memberB/opWorkload:
CacheService.GetTopology RPC over bufconn with 1 active member and 4096 tokens per memberB/opWorkload:
CacheService.GetTopology RPC over bufconn with 3 active members and 128 tokens per memberB/opWorkload:
CacheService.GetTopology RPC over bufconn with 3 active members and 512 tokens per memberB/opWorkload:
CacheService.GetTopology RPC over bufconn with 3 active members and 4096 tokens per memberB/opWorkload:
CacheService.GetTopology RPC over bufconn with 16 active members and 128 tokens per memberB/opWorkload:
CacheService.GetTopology RPC over bufconn with 16 active members and 512 tokens per memberB/opWorkload:
CacheService.GetTopology RPC over bufconn with 16 active members and 4096 tokens per memberB/opGenerated by Perfloop. Measurements and checks.
Note
Medium Risk
Aliasing ring token slices is a concurrency/correctness change: mutating consumers or KV backends that edit slices in place would corrupt topology responses. Coverage is limited to memberlist snapshot replacement and protobuf marshal.
Overview
GetNodeTokensnow returns the current ring snapshot’s token slices instead of allocating and sorting a copy on every topology response. Callers must treat those slices as read-only; ring updates replace the snapshot rather than mutating it in place.Adds a concurrent marshal-vs-memberlist-update regression test and a tagged
GetTopologybufconn benchmark (1/3/16 members × 128/512/4096 tokens), plus a Makefile target to compile that bench without pulling in the rest of CacheService.Reviewed by Cursor Bugbot for commit d71a405. Bugbot is set up for automated code reviews on this repo. Configure here.