1
1
use crate :: api:: github:: Issue ;
2
- use crate :: comparison:: { write_summary_table, ComparisonSummary , Direction } ;
2
+ use crate :: comparison:: { write_summary_table, ComparisonSummary , Direction , Magnitude } ;
3
3
use crate :: load:: { Config , SiteCtxt , TryCommit } ;
4
4
5
5
use anyhow:: Context as _;
@@ -558,36 +558,13 @@ pub async fn post_finished(ctxt: &SiteCtxt) {
558
558
///
559
559
/// `is_master_commit` is used to differentiate messages for try runs and post-merge runs.
560
560
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 ;
567
563
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 ;
584
565
}
585
566
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 {
591
568
let next_steps = match direction {
592
569
Some ( Direction :: Regression | Direction :: Mixed ) => {
593
570
"\n \n **Next Steps**: If you can justify the \
@@ -611,11 +588,7 @@ fn master_run_body(direction: Option<Direction>) -> String {
611
588
)
612
589
}
613
590
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 {
619
592
let next_steps = match direction {
620
593
Some ( Direction :: Regression | Direction :: Mixed ) => {
621
594
"\n \n **Next Steps**: If you can justify the regressions found in \
@@ -643,21 +616,21 @@ compiler perf.{next_steps}
643
616
)
644
617
}
645
618
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
+ ) ;
651
624
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 ( ) ) ,
654
627
"instructions:u" . to_owned ( ) ,
655
628
ctxt,
656
629
)
657
630
. await
658
631
{
659
632
Ok ( Some ( c) ) => c,
660
- _ => return ( String :: from ( "ERROR categorizing benchmark run!" ) , None ) ,
633
+ _ => return String :: from ( "ERROR categorizing benchmark run!" ) ,
661
634
} ;
662
635
663
636
let errors = if !comparison. newly_failed_benchmarks . is_empty ( ) {
@@ -680,29 +653,57 @@ async fn categorize_benchmark(
680
653
let footer = format ! ( "{DISAGREEMENT}{errors}" ) ;
681
654
682
655
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}" ) ;
687
657
}
688
658
689
659
let ( primary_short_summary, primary_direction) = generate_short_summary ( & primary) ;
690
660
let ( secondary_short_summary, secondary_direction) = generate_short_summary ( & secondary) ;
691
661
692
- let mut result = format ! (
662
+ let mut summary = format ! (
693
663
r#"
694
664
- Primary benchmarks: {primary_short_summary}
695
665
- Secondary benchmarks: {secondary_short_summary}
696
666
"#
697
667
) ;
698
- write ! ( result , "\n \n " ) . unwrap ( ) ;
668
+ write ! ( summary , "\n \n " ) . unwrap ( ) ;
699
669
700
- write_summary_table ( & primary, & secondary, true , & mut result ) ;
670
+ write_summary_table ( & primary, & secondary, true , & mut summary ) ;
701
671
702
- write ! ( result , "\n {footer}" ) . unwrap ( ) ;
672
+ write ! ( summary , "\n {footer}" ) . unwrap ( ) ;
703
673
704
674
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
706
707
}
707
708
708
709
fn generate_short_summary ( summary : & ComparisonSummary ) -> ( String , Option < Direction > ) {
0 commit comments