Skip to content

Commit a5976eb

Browse files
authored
Merge pull request #1395 from nnethercote/direction-lattice
`Direction` lattice
2 parents 161b8e9 + 2fddf3a commit a5976eb

File tree

2 files changed

+44
-35
lines changed

2 files changed

+44
-35
lines changed

site/src/comparison.rs

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,10 @@ async fn populate_report(
166166
) {
167167
let (primary, secondary) = comparison.clone().summarize_by_category(&benchmark_map);
168168
// Get the combined direction of the primary and secondary summaries
169-
let direction = match (primary.direction(), secondary.direction()) {
170-
(Some(d1), Some(d2)) if d1 != d2 => Direction::Mixed,
171-
(Some(d), Some(_) | None) => d,
172-
(None, Some(d)) => d,
173-
(None, None) => return,
174-
};
169+
let direction = Direction::join(primary.direction(), secondary.direction());
170+
if direction == Direction::None {
171+
return;
172+
}
175173

176174
let include_in_triage = deserves_attention_icount(&primary, &secondary);
177175

@@ -338,9 +336,9 @@ impl ArtifactComparisonSummary {
338336
}
339337

340338
/// The direction of the changes
341-
pub fn direction(&self) -> Option<Direction> {
339+
pub fn direction(&self) -> Direction {
342340
if self.relevant_comparisons.len() == 0 {
343-
return None;
341+
return Direction::None;
344342
}
345343

346344
let (regressions, improvements): (Vec<&TestResultComparison>, _) = self
@@ -349,11 +347,11 @@ impl ArtifactComparisonSummary {
349347
.partition(|c| c.is_regression());
350348

351349
if regressions.len() == 0 {
352-
return Some(Direction::Improvement);
350+
return Direction::Improvement;
353351
}
354352

355353
if improvements.len() == 0 {
356-
return Some(Direction::Regression);
354+
return Direction::Regression;
357355
}
358356

359357
let total_num = self.relevant_comparisons.len();
@@ -369,28 +367,28 @@ impl ArtifactComparisonSummary {
369367
has_medium_and_above_improvements,
370368
has_medium_and_above_regressions,
371369
) {
372-
(true, true) => return Some(Direction::Mixed),
370+
(true, true) => return Direction::Mixed,
373371
(true, false) => {
374372
if regressions_ratio >= 0.15 {
375-
Some(Direction::Mixed)
373+
Direction::Mixed
376374
} else {
377-
Some(Direction::Improvement)
375+
Direction::Improvement
378376
}
379377
}
380378
(false, true) => {
381379
if regressions_ratio < 0.85 {
382-
Some(Direction::Mixed)
380+
Direction::Mixed
383381
} else {
384-
Some(Direction::Regression)
382+
Direction::Regression
385383
}
386384
}
387385
(false, false) => {
388386
if regressions_ratio >= 0.1 && regressions_ratio <= 0.9 {
389-
Some(Direction::Mixed)
387+
Direction::Mixed
390388
} else if regressions_ratio <= 0.1 {
391-
Some(Direction::Improvement)
389+
Direction::Improvement
392390
} else {
393-
Some(Direction::Regression)
391+
Direction::Regression
394392
}
395393
}
396394
}
@@ -1222,19 +1220,30 @@ impl std::hash::Hash for TestResultComparison {
12221220
// The direction of a performance change
12231221
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
12241222
pub enum Direction {
1223+
None,
12251224
Improvement,
12261225
Regression,
12271226
Mixed,
12281227
}
12291228

1230-
impl std::fmt::Display for Direction {
1231-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1232-
let description = match self {
1233-
Direction::Improvement => "improvement",
1234-
Direction::Regression => "regression",
1235-
Direction::Mixed => "mixed",
1236-
};
1237-
write!(f, "{}", description)
1229+
// The direction of a performance change. Forms a lattice:
1230+
//
1231+
// Mixed
1232+
// / \
1233+
// Improvement Regression
1234+
// \ /
1235+
// None
1236+
//
1237+
impl Direction {
1238+
// Also known as the "least upper bound".
1239+
pub fn join(a: Self, b: Self) -> Self {
1240+
match (a, b) {
1241+
(Self::None, b) => b,
1242+
(a, Self::None) => a,
1243+
(Self::Improvement, Self::Improvement) => Self::Improvement,
1244+
(Self::Regression, Self::Regression) => Self::Regression,
1245+
_ => Self::Mixed,
1246+
}
12381247
}
12391248
}
12401249

site/src/github/comparison_summary.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ async fn summarize_run(
166166
));
167167

168168
let (primary, secondary) = comparison.summarize_by_category(&benchmark_map);
169-
table_written |= write_metric_summary(primary, secondary, hidden, &mut message).await;
169+
table_written |= write_metric_summary(primary, secondary, hidden, &mut message);
170170
}
171171

172172
if table_written {
@@ -177,7 +177,7 @@ async fn summarize_run(
177177
please file an issue in [rust-lang/rustc-perf](https://github.com/rust-lang/rustc-perf/issues/new).";
178178
let footer = format!("{DISAGREEMENT}{errors}");
179179

180-
let direction = inst_primary.direction().or(inst_secondary.direction());
180+
let direction = Direction::join(inst_primary.direction(), inst_secondary.direction());
181181
let next_steps = next_steps(inst_primary, inst_secondary, direction, is_master_commit);
182182

183183
write!(&mut message, "\n{footer}\n{next_steps}").unwrap();
@@ -186,7 +186,7 @@ async fn summarize_run(
186186
}
187187

188188
/// Returns true if a summary table was written to `message`.
189-
async fn write_metric_summary(
189+
fn write_metric_summary(
190190
primary: ArtifactComparisonSummary,
191191
secondary: ArtifactComparisonSummary,
192192
hidden: bool,
@@ -227,12 +227,12 @@ async fn write_metric_summary(
227227
fn next_steps(
228228
primary: ArtifactComparisonSummary,
229229
secondary: ArtifactComparisonSummary,
230-
direction: Option<Direction>,
230+
direction: Direction,
231231
is_master_commit: bool,
232232
) -> String {
233233
let deserves_attention = deserves_attention_icount(&primary, &secondary);
234234
let (is_regression, label) = match (deserves_attention, direction) {
235-
(true, Some(Direction::Regression | Direction::Mixed)) => (true, "+perf-regression"),
235+
(true, Direction::Regression | Direction::Mixed) => (true, "+perf-regression"),
236236
_ => (false, "-perf-regression"),
237237
};
238238

@@ -303,15 +303,15 @@ fn generate_short_summary(summary: &ArtifactComparisonSummary) -> String {
303303
let num_regressions = summary.number_of_regressions();
304304

305305
match summary.direction() {
306-
Some(Direction::Improvement) => format!(
306+
Direction::Improvement => format!(
307307
"✅ relevant {} found",
308308
ending("improvement", num_improvements)
309309
),
310-
Some(Direction::Regression) => format!(
310+
Direction::Regression => format!(
311311
"❌ relevant {} found",
312312
ending("regression", num_regressions)
313313
),
314-
Some(Direction::Mixed) => "mixed results".to_string(),
315-
None => "no relevant changes found".to_string(),
314+
Direction::Mixed => "mixed results".to_string(),
315+
Direction::None => "no relevant changes found".to_string(),
316316
}
317317
}

0 commit comments

Comments
 (0)