Skip to content

storepool: reduce getStoreListFromIDs allocations#171656

Open
shreyasganesh0 wants to merge 1 commit into
cockroachdb:masterfrom
shreyasganesh0:kv/storepool-reduce-getstorelist-allocs
Open

storepool: reduce getStoreListFromIDs allocations#171656
shreyasganesh0 wants to merge 1 commit into
cockroachdb:masterfrom
shreyasganesh0:kv/storepool-reduce-getstorelist-allocs

Conversation

@shreyasganesh0

Copy link
Copy Markdown

getStoreListFromIDs builds a StoreList and a ThrottledStoreReasons slice on every replication and rebalancing decision, growing both result slices via append from a nil start. On clusters with many stores this repeated reallocate-and-copy was observed in #151952 to allocate ~1GB over a 5s allocation profile, adding GC pressure that can hurt foreground latency.

Both slices hold at most one entry per input store ID, so this pre-allocates them to len(storeIDs) capacity. A new BenchmarkGetStoreListFromIDs (50 stores) shows the improvement (same machine):

name                  old           new
GetStoreListFromIDs   81732 B/op    33711 B/op
                      8 allocs/op   3 allocs/op
                      23757 ns/op   12631 ns/op

Epic: none
Fixes: #151952

getStoreListFromIDs builds a StoreList and a ThrottledStoreReasons slice
on every replication and rebalancing decision, growing both result slices
via append from a nil start. On clusters with many stores this repeated
reallocate-and-copy was observed to allocate ~1GB over a 5s allocation
profile, adding GC pressure that can hurt foreground latency.

Both slices hold at most one entry per input store ID, so pre-allocate
them to len(storeIDs) capacity. The new BenchmarkGetStoreListFromIDs
(50 stores) shows the improvement:

    name                  old           new
    GetStoreListFromIDs   81732 B/op    33711 B/op
                          8 allocs/op   3 allocs/op

Epic: none
Fixes: cockroachdb#151952
Release note: None
@shreyasganesh0 shreyasganesh0 requested review from a team as code owners June 14, 2026 18:47
@blathers-crl

blathers-crl Bot commented Jun 14, 2026

Copy link
Copy Markdown

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl Bot added the O-community Originated from the community label Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-community Originated from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

storepool: reduce getStoreListFromIDsLocked() allocations

1 participant