Skip to content

perf: avoid sorting ordered ring tokens - #236

Open
perfloop[bot] wants to merge 2 commits into
mainfrom
perfloop-pr-open-cb5pnxp5z0
Open

perf: avoid sorting ordered ring tokens#236
perfloop[bot] wants to merge 2 commits into
mainfrom
perfloop-pr-open-cb5pnxp5z0

Conversation

@perfloop

@perfloop perfloop Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

What changed

Rebase the topology-token change onto the latest main; the Makefile now keeps both the cleaner and topology benchmark targets.

GetNodeTokens still 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=TestGetNodeTokensPreservesIngressOrderingAndOwnership
  • make test-cache-service-topology
  • focused gofmt and go vet with ocache_topology_benchmark

Workload: 30-second CPU profile of CacheService.GetTopology over gRPC with 8 active nodes and 128 tokens per node

Metric Before After Change
sort_cpu_ppm 32804 0 100% lower

Workload: 5-second CPU profile of CacheService.GetTopology over gRPC with 8 active nodes and 512 tokens per node

Metric Before After Change
sort_cpu_ppm 70064 0 100% lower

Workload: 5-second CPU profile of CacheService.GetTopology over gRPC with 8 active nodes and 1024 tokens per node

Metric Before After Change
sort_cpu_ppm 80038 0 100% lower

Workload: 5-second CPU profile of CacheService.GetTopology over gRPC with 32 active nodes and 128 tokens per node

Metric Before After Change
sort_cpu_ppm 67982 0 100% lower

Workload: 5-second CPU profile of CacheService.GetTopology over gRPC with 32 active nodes and 512 tokens per node

Metric Before After Change
sort_cpu_ppm 69287 0 100% lower

Workload: 5-second CPU profile of CacheService.GetTopology over gRPC with 32 active nodes and 1024 tokens per node

Metric Before After Change
sort_cpu_ppm 83623 0 100% lower
Checks: 4 passed.

Generated 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 GetNodeTokens from re-sorting each node's tokens on every GetTopology response. 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.GetTopology gRPC benchmark, Makefile/measure scripts, and a small pprof decoder (topology-profile) that reports sort CPU share. Service files are split with ocache_topology_benchmark so 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.

@greptile-apps

greptile-apps Bot commented Aug 21, 2026

Copy link
Copy Markdown

Greptile Summary

The 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/5

The 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

Filename Overview
coordinator/ring/ring.go Removes sorting from GetNodeTokens while retaining defensive copies; tests establish sorted ring-reader output for relevant descriptor paths.
coordinator/ring/topology_test.go Verifies token normalization for generated, persisted legacy, and deserialized legacy descriptors and confirms returned slices do not alias ring state.
server/service/service.go Separates topology-independent service data behind a benchmark-excluding build constraint without changing the ordinary service implementation.
server/service/topology.go Moves CacheService and the production GetTopology implementation into an always-compiled file for benchmark reuse.
server/service/topology_benchmark_test.go Benchmarks the production topology RPC over an in-process gRPC transport and validates node counts, token counts, uniqueness, and ordering.
server/cmd/topology-profile/main.go Adds a bounded protobuf profile parser that attributes CPU samples to sorting beneath GetNodeTokens.
scripts/measure-topology-benchmark.sh Adds validated CPU and latency benchmark execution with cleanup and machine-readable metric emission.
Makefile Adds dedicated build and test entry points for topology benchmark artifacts.

Reviews (1): Last reviewed commit: "perf: avoid sorting ordered ring tokens" | Re-trigger Greptile

efirs
efirs previously approved these changes Aug 21, 2026
@perfloop
perfloop Bot force-pushed the perfloop-pr-open-cb5pnxp5z0 branch from 1bc0e85 to 3ae618f Compare August 22, 2026 01:22

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread coordinator/ring/ring.go
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
@perfloop
perfloop Bot force-pushed the perfloop-pr-open-cb5pnxp5z0 branch from 3ae618f to 50a0c7a Compare August 22, 2026 21:27
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