Skip to content

Commit 602a116

Browse files
authored
[chore] initialize the map with a given length to avoid memory copy of the map on growth (#3667)
1 parent a8bdd11 commit 602a116

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cmd/otel-allocator/collector/collector.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ func (k *Watcher) rateLimitedCollectorHandler(notify chan struct{}, store cache.
126126

127127
// runOnCollectors runs the provided function on the set of collectors from the Store.
128128
func (k *Watcher) runOnCollectors(store cache.Store, fn func(collectors map[string]*allocation.Collector)) {
129-
collectorMap := map[string]*allocation.Collector{}
130129
objects := store.List()
130+
collectorMap := make(map[string]*allocation.Collector, len(objects))
131131
for _, obj := range objects {
132132
pod := obj.(*v1.Pod)
133133
if pod.Spec.NodeName == "" {

0 commit comments

Comments
 (0)