cockroachdb / cockroachdb/cockroach
Improve allocations for rarely used histograms
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
During each Tick of a histogram metric, the current and previous windows are rotated such that `prev = cur`, `cur = NewHistogram` ([see code here](https://github.com/cockroachdb/cockroach/blob/baea7bbd0b591e34131334d4722101e6f4340030/pkg/util/metric/metric.go#L476)). For rarely used histograms, its often the case that both `prev` and `cur` have not been modified since the last tick, so rotating the windows is unnecessary.
Ideally, we would avoid allocating a new histogram in this situation. Since this Tick happens frequently (every ~5s today I believe) for every histogram metric, this unnecessary allocation can significantly affect the overall number of allocs in the system.
See https://github.com/cockroachdb/cockroach/pull/161818#discussion_r2731211615 for more context.
Jira issue: CRDB-59125
Contributor guide
Assessment
This issue has not been assessed yet.