Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code optimization: deal with error first to prevent unnecessary computing #110372

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions pkg/scheduler/framework/plugins/podtopologyspread/filtering.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,6 @@ func (pl *PodTopologySpread) Filter(ctx context.Context, cycleState *framework.C
return framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonNodeLabelNotMatch)
}

selfMatchNum := 0
if c.Selector.Matches(podLabelSet) {
selfMatchNum = 1
}

pair := topologyPair{key: tpKey, value: tpVal}

// judging criteria:
// 'existing matching num' + 'if self-match (1 or 0)' - 'global minimum' <= 'maxSkew'
minMatchNum, err := s.minMatchNum(tpKey, c.MinDomains, pl.enableMinDomainsInPodTopologySpread)
Expand All @@ -359,6 +352,12 @@ func (pl *PodTopologySpread) Filter(ctx context.Context, cycleState *framework.C
continue
}

selfMatchNum := 0
Copy link
Member

@kerthcet kerthcet Jun 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to add some explanations what this PR for. I guess you want to fail fast here, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lokichoggio It's weird to call it "fail fast". I guess you meant "move the definition of variables to their most recent usage"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

em...... yes, fail fast is a little weird, but I think the most valuable thing here is to prevent unnecessary computing when error in calculating minMatchNum. Whatever, fail fast is not that accurate.

if c.Selector.Matches(podLabelSet) {
selfMatchNum = 1
}

pair := topologyPair{key: tpKey, value: tpVal}
matchNum := 0
if tpCount, ok := s.TpPairToMatchNum[pair]; ok {
matchNum = tpCount
Expand Down