11use crate :: api:: github:: Issue ;
2- use crate :: comparison:: { write_summary_table, ComparisonSummary , Direction } ;
2+ use crate :: comparison:: { write_summary_table, ComparisonSummary , Direction , Magnitude } ;
33use crate :: load:: { Config , SiteCtxt , TryCommit } ;
44
55use 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.
560560async 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
708709fn generate_short_summary ( summary : & ComparisonSummary ) -> ( String , Option < Direction > ) {
0 commit comments