Skip to content

Commit 6a22d2b

Browse files
committed
Only label PRs as perf regressions if we're confident enough
1 parent b0145e1 commit 6a22d2b

File tree

2 files changed

+60
-51
lines changed

2 files changed

+60
-51
lines changed

site/src/comparison.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,14 @@ impl ComparisonSummary {
337337
pub fn is_relevant(&self) -> bool {
338338
!self.is_empty()
339339
}
340+
341+
pub fn num_changes(&self) -> usize {
342+
self.relevant_comparisons.len()
343+
}
344+
345+
pub fn largest_change(&self) -> Option<&TestResultComparison> {
346+
self.relevant_comparisons.first()
347+
}
340348
}
341349

342350
async fn write_triage_summary(
@@ -984,7 +992,7 @@ impl TestResultComparison {
984992
///
985993
/// This is the average of the absolute magnitude of the change
986994
/// and the amount above the significance threshold.
987-
fn magnitude(&self) -> Magnitude {
995+
pub fn magnitude(&self) -> Magnitude {
988996
let change = self.relative_change().abs();
989997
let threshold = self.significance_threshold();
990998
let over_threshold = if change < threshold * 1.5 {

site/src/github.rs

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::api::github::Issue;
2-
use crate::comparison::{write_summary_table, ComparisonSummary, Direction};
2+
use crate::comparison::{write_summary_table, ComparisonSummary, Direction, Magnitude};
33
use crate::load::{Config, SiteCtxt, TryCommit};
44

55
use anyhow::Context as _;
@@ -558,36 +558,13 @@ pub async fn post_finished(ctxt: &SiteCtxt) {
558558
///
559559
/// `is_master_commit` is used to differentiate messages for try runs and post-merge runs.
560560
async fn post_comparison_comment(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit: bool) {
561-
let comparison_url = format!(
562-
"https://perf.rust-lang.org/compare.html?start={}&end={}",
563-
commit.parent_sha, commit.sha
564-
);
565-
let (summary, direction) =
566-
categorize_benchmark(ctxt, commit.sha.clone(), commit.parent_sha).await;
561+
let pr = commit.pr;
562+
let body = summarize_run(ctxt, commit, is_master_commit).await;
567563

568-
let body = format!(
569-
"Finished benchmarking commit ({sha}): [comparison url]({url}).
570-
571-
**Summary**: {summary}
572-
{rest}",
573-
sha = commit.sha,
574-
url = comparison_url,
575-
summary = summary,
576-
rest = if is_master_commit {
577-
master_run_body(direction)
578-
} else {
579-
try_run_body(direction)
580-
}
581-
);
582-
583-
post_comment(&ctxt.config, commit.pr, body).await;
564+
post_comment(&ctxt.config, pr, body).await;
584565
}
585566

586-
fn master_run_body(direction: Option<Direction>) -> String {
587-
let label = match direction {
588-
Some(Direction::Regression | Direction::Mixed) => "+perf-regression",
589-
Some(Direction::Improvement) | None => "-perf-regression",
590-
};
567+
fn master_run_body(label: &str, direction: Option<Direction>) -> String {
591568
let next_steps = match direction {
592569
Some(Direction::Regression | Direction::Mixed) => {
593570
"\n\n**Next Steps**: If you can justify the \
@@ -611,11 +588,7 @@ fn master_run_body(direction: Option<Direction>) -> String {
611588
)
612589
}
613590

614-
fn try_run_body(direction: Option<Direction>) -> String {
615-
let label = match direction {
616-
Some(Direction::Regression | Direction::Mixed) => "+perf-regression",
617-
Some(Direction::Improvement) | None => "-perf-regression",
618-
};
591+
fn try_run_body(label: &str, direction: Option<Direction>) -> String {
619592
let next_steps = match direction {
620593
Some(Direction::Regression | Direction::Mixed) => {
621594
"\n\n**Next Steps**: If you can justify the regressions found in \
@@ -643,21 +616,21 @@ compiler perf.{next_steps}
643616
)
644617
}
645618

646-
async fn categorize_benchmark(
647-
ctxt: &SiteCtxt,
648-
commit_sha: String,
649-
parent_sha: String,
650-
) -> (String, Option<Direction>) {
619+
async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit: bool) -> String {
620+
let comparison_url = format!(
621+
"https://perf.rust-lang.org/compare.html?start={}&end={}",
622+
commit.parent_sha, commit.sha
623+
);
651624
let comparison = match crate::comparison::compare(
652-
collector::Bound::Commit(parent_sha),
653-
collector::Bound::Commit(commit_sha),
625+
collector::Bound::Commit(commit.parent_sha),
626+
collector::Bound::Commit(commit.sha.clone()),
654627
"instructions:u".to_owned(),
655628
ctxt,
656629
)
657630
.await
658631
{
659632
Ok(Some(c)) => c,
660-
_ => return (String::from("ERROR categorizing benchmark run!"), None),
633+
_ => return String::from("ERROR categorizing benchmark run!"),
661634
};
662635

663636
let errors = if !comparison.newly_failed_benchmarks.is_empty() {
@@ -680,29 +653,57 @@ async fn categorize_benchmark(
680653
let footer = format!("{DISAGREEMENT}{errors}");
681654

682655
if !primary.is_relevant() && !secondary.is_relevant() {
683-
return (
684-
format!("This benchmark run did not return any relevant results.\n\n{footer}"),
685-
None,
686-
);
656+
return format!("This benchmark run did not return any relevant results.\n\n{footer}");
687657
}
688658

689659
let (primary_short_summary, primary_direction) = generate_short_summary(&primary);
690660
let (secondary_short_summary, secondary_direction) = generate_short_summary(&secondary);
691661

692-
let mut result = format!(
662+
let mut summary = format!(
693663
r#"
694664
- Primary benchmarks: {primary_short_summary}
695665
- Secondary benchmarks: {secondary_short_summary}
696666
"#
697667
);
698-
write!(result, "\n\n").unwrap();
668+
write!(summary, "\n\n").unwrap();
699669

700-
write_summary_table(&primary, &secondary, true, &mut result);
670+
write_summary_table(&primary, &secondary, true, &mut summary);
701671

702-
write!(result, "\n{footer}").unwrap();
672+
write!(summary, "\n{footer}").unwrap();
703673

704674
let direction = primary_direction.or(secondary_direction);
705-
(result, direction)
675+
// are we confident enough this is a real change
676+
let confident_enough = match (primary.largest_change(), secondary.largest_change()) {
677+
(Some(c), _) if c.magnitude() >= Magnitude::Medium => true,
678+
(_, Some(c)) if c.magnitude() >= Magnitude::Medium => true,
679+
_ => {
680+
let primary_n = primary.num_changes();
681+
let secondary_n = secondary.num_changes();
682+
(primary_n * 2 + secondary_n) >= 6
683+
}
684+
};
685+
686+
let label = match (confident_enough, &direction) {
687+
(true, Some(Direction::Regression | Direction::Mixed)) => "+perf-regression",
688+
(true, Some(Direction::Improvement) | None) => "-perf-regression",
689+
(false, _) => "-perf-regression",
690+
};
691+
692+
let body = format!(
693+
"Finished benchmarking commit ({sha}): [comparison url]({url}).
694+
695+
**Summary**: {summary}
696+
{rest}",
697+
sha = commit.sha,
698+
url = comparison_url,
699+
summary = summary,
700+
rest = if is_master_commit {
701+
master_run_body(label, direction)
702+
} else {
703+
try_run_body(label, direction)
704+
}
705+
);
706+
body
706707
}
707708

708709
fn generate_short_summary(summary: &ComparisonSummary) -> (String, Option<Direction>) {

0 commit comments

Comments
 (0)