Skip to content

Commit 93fc02c

Browse files
Set initial map size
Signed-off-by: Aldo Culquicondor <[email protected]>
1 parent 65d9f81 commit 93fc02c

File tree

1 file changed

+10
-1
lines changed
  • pkg/scheduler/framework/plugins/podtopologyspread

1 file changed

+10
-1
lines changed

pkg/scheduler/framework/plugins/podtopologyspread/filtering.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func (pl *PodTopologySpread) calPreFilterState(pod *v1.Pod) (*preFilterState, er
223223
s := preFilterState{
224224
Constraints: constraints,
225225
TpKeyToCriticalPaths: make(map[string]*criticalPaths, len(constraints)),
226-
TpPairToMatchNum: make(map[topologyPair]*int32),
226+
TpPairToMatchNum: make(map[topologyPair]*int32, sizeHeuristic(len(allNodes), constraints)),
227227
}
228228
for _, n := range allNodes {
229229
node := n.Node()
@@ -328,3 +328,12 @@ func (pl *PodTopologySpread) Filter(ctx context.Context, cycleState *framework.C
328328

329329
return nil
330330
}
331+
332+
func sizeHeuristic(nodes int, constraints []topologySpreadConstraint) int {
333+
for _, c := range constraints {
334+
if c.TopologyKey == v1.LabelHostname {
335+
return nodes
336+
}
337+
}
338+
return 0
339+
}

0 commit comments

Comments
 (0)