perf: avoid sorting ordered ring tokens - #236
Conversation
Greptile SummaryThe PR removes redundant per-request token sorting after ring ingress normalization while preserving copy ownership. It also adds topology-specific benchmarks, profiling utilities, build targets, and coverage for generated, persisted, and deserialized legacy descriptors. Confidence Score: 5/5The PR appears safe to merge with no actionable correctness, security, or build failures identified. Ring-reader normalization is exercised for unsorted legacy descriptors, token slices remain independently owned, clients retain their own global sort, and the benchmark-only service boundary is isolated to its intended tagged test build. Important Files Changed
Reviews (1): Last reviewed commit: "perf: avoid sorting ordered ring tokens" | Re-trigger Greptile |
1bc0e85 to
3ae618f
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3ae618f. Configure here.
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
3ae618f to
50a0c7a
Compare

What changed
Rebase the topology-token change onto the latest
main; the Makefile now keeps both the cleaner and topology benchmark targets.GetNodeTokensstill makes an ownership copy, but no longer re-sorts each active node's tokens for every topology response. Ring materialization keeps generated, persisted legacy, and deserialized legacy descriptors ordered, and the response tests preserve that contract.The copy remains so callers cannot mutate ring-owned token slices.
Verification
make test-coordinator TEST=TestGetNodeTokensPreservesIngressOrderingAndOwnershipmake test-cache-service-topologygofmtandgo vetwithocache_topology_benchmarkWorkload:
30-second CPU profile of CacheService.GetTopology over gRPC with 8 active nodes and 128 tokens per nodesort_cpu_ppmWorkload:
5-second CPU profile of CacheService.GetTopology over gRPC with 8 active nodes and 512 tokens per nodesort_cpu_ppmWorkload:
5-second CPU profile of CacheService.GetTopology over gRPC with 8 active nodes and 1024 tokens per nodesort_cpu_ppmWorkload:
5-second CPU profile of CacheService.GetTopology over gRPC with 32 active nodes and 128 tokens per nodesort_cpu_ppmWorkload:
5-second CPU profile of CacheService.GetTopology over gRPC with 32 active nodes and 512 tokens per nodesort_cpu_ppmWorkload:
5-second CPU profile of CacheService.GetTopology over gRPC with 32 active nodes and 1024 tokens per nodesort_cpu_ppmGenerated by Perfloop. Measurements and checks.
Note
Medium Risk
Touches cluster topology token lists used for client routing. The behavioral change is small (drop redundant sort, keep copy) and is covered by ordering/ownership tests, but incorrect ordering would misroute keys.
Overview
Stops
GetNodeTokensfrom re-sorting each node's tokens on everyGetTopologyresponse. Tokens stay copied so callers cannot mutate ring-owned slices; ordering is trusted from dskit ring materialization (generated, persisted, and legacy unsorted wire tokens).Adds a tagged
CacheService.GetTopologygRPC benchmark, Makefile/measure scripts, and a small pprof decoder (topology-profile) that reports sort CPU share. Service files are split withocache_topology_benchmarkso the bench binary can compile without the storage data path.Reviewed by Cursor Bugbot for commit 50a0c7a. Bugbot is set up for automated code reviews on this repo. Configure here.