From 93fc02cf54021dcb3ff9fe9644842ccdbadb5ee7 Mon Sep 17 00:00:00 2001 From: Aldo Culquicondor Date: Mon, 30 Mar 2020 17:10:48 -0400 Subject: [PATCH] Set initial map size Signed-off-by: Aldo Culquicondor --- .../framework/plugins/podtopologyspread/filtering.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/scheduler/framework/plugins/podtopologyspread/filtering.go b/pkg/scheduler/framework/plugins/podtopologyspread/filtering.go index 761c5cce6a4..9d716c3ee8f 100644 --- a/pkg/scheduler/framework/plugins/podtopologyspread/filtering.go +++ b/pkg/scheduler/framework/plugins/podtopologyspread/filtering.go @@ -223,7 +223,7 @@ func (pl *PodTopologySpread) calPreFilterState(pod *v1.Pod) (*preFilterState, er s := preFilterState{ Constraints: constraints, TpKeyToCriticalPaths: make(map[string]*criticalPaths, len(constraints)), - TpPairToMatchNum: make(map[topologyPair]*int32), + TpPairToMatchNum: make(map[topologyPair]*int32, sizeHeuristic(len(allNodes), constraints)), } for _, n := range allNodes { node := n.Node() @@ -328,3 +328,12 @@ func (pl *PodTopologySpread) Filter(ctx context.Context, cycleState *framework.C return nil } + +func sizeHeuristic(nodes int, constraints []topologySpreadConstraint) int { + for _, c := range constraints { + if c.TopologyKey == v1.LabelHostname { + return nodes + } + } + return 0 +}