cockroachdb / cockroachdb/cockroach

storepool: reduce getStoreListFromIDsLocked() allocations

Open
#151,952 1 comment 0 reactions 0 assignees View on GitHub
C-enhancement E-starter T-kv
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

Recently in one of the escalation, we noticed that the function [getStoreListFromIDsLocked()](https://github.com/cockroachdb/cockroach/blob/f76fdd60c25a041a136e20ef821af3b5c7bb08cf/pkg/kv/kvserver/allocator/storepool/store_pool.go#L1147C22-L1147C48) allocated about 1GB of data based on a 5s allocs profile diff. This is not ideal because this could potentially impact the foreground latency as it will increase the frequency of GC kicking in.

Diff example:

Image

The hot slice seems to be `storeDescriptors []`

Some ideas to consider:

1) If we know the size of the slices, or can estimate it, we probably can create the slice with that size. This should help avoid extra allocations as we are adding more and more items to the slice, and the size of the slice is increasing. This should save both allocations + time where we copy bytes from one smaller slice to a larger slice.

2) If the contents of the slices doesn't change much between each invocation, we can probably do something smart about it. For example, if we can hang the slice somewhere, along a map that maps from storeID to an index in the slice. This way, we can know if there is a new store while we are iterating over the stores (if the storeID doesn't exist in the map), or if it does, we can use the map to know the index at which the storeDesc exists in the slice.

Jira issue: CRDB-53552

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.