Update metrics.go

Pre-allocate bucketsCounter slice with make() to avoid multiple 
reallocations during initialization. This matches the pattern used 
elsewhere in the codebase and eliminates unnecessary memory allocations 
for the 17-element slice.
This commit is contained in:
Adam 2025-12-21 16:36:59 +01:00 committed by GitHub
parent 2e5cd21edf
commit 1d2accd2f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -40,8 +40,9 @@ var (
)
func init() {
bucketsCounter = make([]*metrics.Counter, nBuckets)
for i := 0; i < nBuckets; i++ {
bucketsCounter = append(bucketsCounter, metrics.NewRegisteredCounter(fmt.Sprintf("%s/bucket/%d/count", moduleName, i), nil))
bucketsCounter[i] = metrics.NewRegisteredCounter(fmt.Sprintf("%s/bucket/%d/count", moduleName, i), nil)
}
}