Skip to content

Commit 870445d

Browse files
authored
Merge pull request #1415 from nnethercote/clarify-overall-result
Clarify the overall result in the GitHub comment.
2 parents d6d041f + 2bd9b6a commit 870445d

File tree

2 files changed

+60
-96
lines changed

2 files changed

+60
-96
lines changed

site/src/comparison.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,16 +394,6 @@ impl ArtifactComparisonSummary {
394394
}
395395
}
396396

397-
/// The number of improvements that were found to be significant and relevant
398-
pub fn number_of_improvements(&self) -> usize {
399-
self.num_improvements
400-
}
401-
402-
/// The number of regressions that were found to be significant and relevant
403-
pub fn number_of_regressions(&self) -> usize {
404-
self.num_regressions
405-
}
406-
407397
/// Arithmetic mean of all improvements as a percent
408398
pub fn arithmetic_mean_of_improvements(&self) -> f64 {
409399
self.arithmetic_mean(self.improvements())
@@ -1248,8 +1238,8 @@ pub enum Direction {
12481238
//
12491239
impl Direction {
12501240
// Also known as the "least upper bound".
1251-
pub fn join(a: Self, b: Self) -> Self {
1252-
match (a, b) {
1241+
pub fn join(self, other: Self) -> Self {
1242+
match (self, other) {
12531243
(Self::None, b) => b,
12541244
(a, Self::None) => a,
12551245
(Self::Improvement, Self::Improvement) => Self::Improvement,

site/src/github/comparison_summary.rs

Lines changed: 58 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async fn summarize_run(
114114
let benchmark_map = ctxt.get_benchmark_category_map().await;
115115

116116
let mut message = format!(
117-
"Finished benchmarking commit ({sha}): [comparison url]({comparison_url}).\n\n",
117+
"Finished benchmarking commit ({sha}): [comparison URL]({comparison_url}).\n\n",
118118
sha = commit.sha,
119119
comparison_url = make_comparison_url(&commit, Metric::InstructionsUser)
120120
);
@@ -133,116 +133,115 @@ async fn summarize_run(
133133
} else {
134134
String::new()
135135
};
136+
136137
let (inst_primary, inst_secondary) = inst_comparison
137138
.clone()
138139
.summarize_by_category(&benchmark_map);
139140

141+
let direction = inst_primary.direction().join(inst_secondary.direction());
142+
let overall_result = match direction {
143+
Direction::Improvement => "✅ improvements",
144+
Direction::Regression => "❌ regressions",
145+
Direction::Mixed => "❌✅ regressions and improvements",
146+
Direction::None => "no relevant changes",
147+
};
148+
let is_regression = deserves_attention_icount(&inst_primary, &inst_secondary)
149+
&& matches!(direction, Direction::Regression | Direction::Mixed);
150+
151+
writeln!(
152+
&mut message,
153+
"### Overall result: {}{}\n",
154+
overall_result,
155+
if is_regression {
156+
" - ACTION NEEDED"
157+
} else {
158+
" - no action needed"
159+
},
160+
)
161+
.unwrap();
162+
163+
let next_steps = if is_master_commit {
164+
master_run_body(is_regression)
165+
} else {
166+
try_run_body(is_regression)
167+
};
168+
writeln!(&mut message, "{next_steps}\n").unwrap();
169+
170+
if !errors.is_empty() {
171+
writeln!(&mut message, "\n{errors}").unwrap();
172+
}
173+
140174
let mut table_written = false;
141175
let metrics = vec![
142176
(
143177
"Instruction count",
144178
Metric::InstructionsUser,
145-
false,
179+
true, // highly reliable
146180
inst_comparison,
147181
),
148182
(
149183
"Max RSS (memory usage)",
150184
Metric::MaxRSS,
151-
true,
185+
false, // not highly reliable
152186
calculate_metric_comparison(ctxt, &commit, Metric::MaxRSS).await?,
153187
),
154188
(
155189
"Cycles",
156190
Metric::CyclesUser,
157-
true,
191+
false, // not highly reliable
158192
calculate_metric_comparison(ctxt, &commit, Metric::CyclesUser).await?,
159193
),
160194
];
161195

162-
for (title, metric, hidden, comparison) in metrics {
196+
for (title, metric, highly_reliable, comparison) in metrics {
163197
message.push_str(&format!(
164198
"\n### [{title}]({})\n",
165199
make_comparison_url(&commit, metric)
166200
));
167201

168202
let (primary, secondary) = comparison.summarize_by_category(&benchmark_map);
169-
table_written |= write_metric_summary(primary, secondary, hidden, &mut message);
203+
table_written |= write_metric_summary(primary, secondary, highly_reliable, &mut message);
170204
}
171205

172206
if table_written {
173207
write_summary_table_footer(&mut message);
174208
}
175209

176-
const DISAGREEMENT: &str = "If you disagree with this performance assessment, \
177-
please file an issue in [rust-lang/rustc-perf](https://github.com/rust-lang/rustc-perf/issues/new).";
178-
let footer = format!("{DISAGREEMENT}{errors}");
179-
180-
let direction = Direction::join(inst_primary.direction(), inst_secondary.direction());
181-
let next_steps = next_steps(inst_primary, inst_secondary, direction, is_master_commit);
182-
183-
write!(&mut message, "\n{footer}\n{next_steps}").unwrap();
184-
185210
Ok(message)
186211
}
187212

188213
/// Returns true if a summary table was written to `message`.
189214
fn write_metric_summary(
190215
primary: ArtifactComparisonSummary,
191216
secondary: ArtifactComparisonSummary,
192-
hidden: bool,
217+
highly_reliable: bool,
193218
message: &mut String,
194219
) -> bool {
195220
if !primary.is_relevant() && !secondary.is_relevant() {
196221
message
197222
.push_str("This benchmark run did not return any relevant results for this metric.\n");
198223
false
199224
} else {
200-
let primary_short_summary = generate_short_summary(&primary);
201-
let secondary_short_summary = generate_short_summary(&secondary);
202-
203-
if hidden {
225+
if highly_reliable {
226+
message.push_str(
227+
"This is a highly reliable metric that was used to determine the \
228+
overall result at the top of this comment.\n\n",
229+
);
230+
write_summary_table(&primary, &secondary, true, false, message);
231+
} else {
232+
// `<details>` means it is hidden, requiring a click to reveal.
204233
message.push_str("<details>\n<summary>Results</summary>\n\n");
205-
}
206-
207-
write!(
208-
message,
209-
r#"
210-
- Primary benchmarks: {primary_short_summary}
211-
- Secondary benchmarks: {secondary_short_summary}
212-
213-
"#
214-
)
215-
.unwrap();
216-
217-
write_summary_table(&primary, &secondary, true, false, message);
218-
219-
if hidden {
234+
message.push_str(
235+
"This is a less reliable metric that may be of interest but was not \
236+
used to determine the overall result at the top of this comment.\n\n",
237+
);
238+
write_summary_table(&primary, &secondary, true, false, message);
220239
message.push_str("</details>\n");
221240
}
222-
223241
true
224242
}
225243
}
226244

227-
fn next_steps(
228-
primary: ArtifactComparisonSummary,
229-
secondary: ArtifactComparisonSummary,
230-
direction: Direction,
231-
is_master_commit: bool,
232-
) -> String {
233-
let deserves_attention = deserves_attention_icount(&primary, &secondary);
234-
let (is_regression, label) = match (deserves_attention, direction) {
235-
(true, Direction::Regression | Direction::Mixed) => (true, "+perf-regression"),
236-
_ => (false, "-perf-regression"),
237-
};
238-
239-
if is_master_commit {
240-
master_run_body(is_regression)
241-
} else {
242-
try_run_body(label)
243-
}
244-
}
245-
246245
fn master_run_body(is_regression: bool) -> String {
247246
if is_regression {
248247
"
@@ -265,8 +264,8 @@ cc @rust-lang/wg-compiler-performance
265264
.to_string()
266265
}
267266

268-
fn try_run_body(label: &str) -> String {
269-
let next_steps = if label.starts_with("+") {
267+
fn try_run_body(is_regression: bool) -> String {
268+
let next_steps = if is_regression {
270269
"\n\n**Next Steps**: If you can justify the regressions found in \
271270
this try perf run, please indicate this with \
272271
`@rustbot label: +perf-regression-triaged` along with \
@@ -277,6 +276,7 @@ fn try_run_body(label: &str) -> String {
277276
""
278277
};
279278

279+
let sign = if is_regression { "+" } else { "-" };
280280
format!(
281281
"
282282
Benchmarking this pull request likely means that it is \
@@ -286,32 +286,6 @@ for rollup, we strongly recommend not doing so since this PR may lead to changes
286286
compiler perf.{next_steps}
287287
288288
@bors rollup=never
289-
@rustbot label: +S-waiting-on-review -S-waiting-on-perf {label}",
289+
@rustbot label: +S-waiting-on-review -S-waiting-on-perf {sign}perf-regression",
290290
)
291291
}
292-
293-
fn generate_short_summary(summary: &ArtifactComparisonSummary) -> String {
294-
// Add an "s" to a word unless there's only one.
295-
fn ending(word: &'static str, count: usize) -> std::borrow::Cow<'static, str> {
296-
if count == 1 {
297-
return word.into();
298-
}
299-
format!("{}s", word).into()
300-
}
301-
302-
let num_improvements = summary.number_of_improvements();
303-
let num_regressions = summary.number_of_regressions();
304-
305-
match summary.direction() {
306-
Direction::Improvement => format!(
307-
"✅ relevant {} found",
308-
ending("improvement", num_improvements)
309-
),
310-
Direction::Regression => format!(
311-
"❌ relevant {} found",
312-
ending("regression", num_regressions)
313-
),
314-
Direction::Mixed => "mixed results".to_string(),
315-
Direction::None => "no relevant changes found".to_string(),
316-
}
317-
}

0 commit comments

Comments
 (0)