Skip to content

Commit

Permalink
[chore] initialize the map with a given length to avoid memory copy o…
Browse files Browse the repository at this point in the history
…f the map on growth (open-telemetry#3667)
  • Loading branch information
atoulme authored Jan 25, 2025
1 parent a8bdd11 commit 602a116
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/otel-allocator/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down

0 comments on commit 602a116

Please sign in to comment.