From 1d2accd2f49f66e6d62773e8f36d90708fac899e Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 21 Dec 2025 16:36:59 +0100 Subject: [PATCH] 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. --- p2p/discover/metrics.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/p2p/discover/metrics.go b/p2p/discover/metrics.go index 5d4c953c90..bd06efd5e0 100644 --- a/p2p/discover/metrics.go +++ b/p2p/discover/metrics.go @@ -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) } }