From 602a11699de587a7c1aadf4aec2c1e5b5edb4a96 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Sat, 25 Jan 2025 02:01:39 -0800 Subject: [PATCH] [chore] initialize the map with a given length to avoid memory copy of the map on growth (#3667) --- cmd/otel-allocator/collector/collector.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/otel-allocator/collector/collector.go b/cmd/otel-allocator/collector/collector.go index 8814e38797..1a33aed1b9 100644 --- a/cmd/otel-allocator/collector/collector.go +++ b/cmd/otel-allocator/collector/collector.go @@ -126,8 +126,8 @@ func (k *Watcher) rateLimitedCollectorHandler(notify chan struct{}, store cache. // runOnCollectors runs the provided function on the set of collectors from the Store. func (k *Watcher) runOnCollectors(store cache.Store, fn func(collectors map[string]*allocation.Collector)) { - collectorMap := map[string]*allocation.Collector{} objects := store.List() + collectorMap := make(map[string]*allocation.Collector, len(objects)) for _, obj := range objects { pod := obj.(*v1.Pod) if pod.Spec.NodeName == "" {