@@ -37,44 +37,30 @@ async fn create_benchmark_request_master_commits(
3737 Ok ( ( ) )
3838}
3939
40- /// For getting the priority of the request type;
41- /// - Release
42- /// - Master
43- /// - Try
44- fn benchmark_request_commit_type_rank ( commit_type : & BenchmarkRequestType ) -> u8 {
45- match commit_type {
46- BenchmarkRequestType :: Release { .. } => 0 ,
47- BenchmarkRequestType :: Master { .. } => 1 ,
48- BenchmarkRequestType :: Try { .. } => 2 ,
49- }
50- }
51-
52- /// Sorts the priority order of the queue. It assumes that the only status
53- /// is `ArtifactsReady`
54- fn sort_benchmark_requests < ' a > (
55- done : & mut HashSet < String > ,
56- unordered_queue : & ' a mut [ BenchmarkRequest ] ,
57- ) -> & ' a [ BenchmarkRequest ] {
40+ /// Sorts try and master requests that are in the `ArtifactsReady` status.
41+ /// Doesn't consider in-progress requests or release artifacts.
42+ fn sort_benchmark_requests < ' a > ( done : & HashSet < String > , request_queue : & ' a mut [ BenchmarkRequest ] ) {
5843 // A topological sort, where each "level" is additionally altered such that
5944 // try commits come first, and then sorted by PR # (as a rough heuristic for
6045 // earlier requests).
46+ let mut done: HashSet < & str > = done. iter ( ) . map ( |x| x. as_str ( ) ) . collect ( ) ;
6147
6248 // Ensure all the items are ready to be sorted, if they are not this is
6349 // undefined behaviour
64- assert ! ( unordered_queue
65- . iter ( )
66- . all ( |bmr| bmr . status == BenchmarkRequestStatus :: ArtifactsReady ) ) ;
67-
68- // Ensure the queue is ordered by status and the `commit_type`
69- unordered_queue
70- . sort_unstable_by_key ( |bmr| ( benchmark_request_commit_type_rank ( & bmr . commit_type ) ) ) ;
50+ assert ! ( request_queue . iter ( ) . all ( |bmr| {
51+ bmr . status == BenchmarkRequestStatus :: ArtifactsReady
52+ && matches! (
53+ bmr . commit_type ,
54+ BenchmarkRequestType :: Master { .. } | BenchmarkRequestType :: Try { .. }
55+ )
56+ } ) ) ;
7157
7258 let mut finished = 0 ;
73- while finished < unordered_queue . len ( ) {
59+ while finished < request_queue . len ( ) {
7460 // The next level is those elements in the unordered queue which
7561 // are ready to be benchmarked (i.e., those with parent in done or no
7662 // parent).
77- let level_len = partition_in_place ( unordered_queue [ finished..] . iter_mut ( ) , |bmr| {
63+ let level_len = partition_in_place ( request_queue [ finished..] . iter_mut ( ) , |bmr| {
7864 bmr. parent_sha ( ) . is_none_or ( |parent| done. contains ( parent) )
7965 } ) ;
8066
@@ -83,33 +69,43 @@ fn sort_benchmark_requests<'a>(
8369 // let the commits be benchmarked in the current order that we have, these benchmark runs
8470 // just won't have a parent result available.
8571 if level_len == 0 {
86- return unordered_queue;
72+ log:: warn!( "No commit is ready for benchmarking" ) ;
73+ #[ cfg( test) ]
74+ {
75+ panic ! ( "No commit is ready for benchmarking" ) ;
76+ }
77+ return ;
8778 }
8879
89- let level = & mut unordered_queue[ finished..] [ ..level_len] ;
80+ // Everything in level has the same topological order, then we sort based on heuristics
81+ let level = & mut request_queue[ finished..] [ ..level_len] ;
9082 level. sort_unstable_by_key ( |bmr| {
9183 (
92- bmr. parent_sha ( ) . is_some ( ) ,
84+ // Order master commits before try commits
85+ match bmr. commit_type {
86+ BenchmarkRequestType :: Try { .. } => 1 ,
87+ BenchmarkRequestType :: Master { .. } => 0 ,
88+ BenchmarkRequestType :: Release { .. } => unreachable ! ( ) ,
89+ } ,
9390 * bmr. pr ( ) . unwrap_or ( & 0 ) ,
9491 bmr. created_at ,
95- bmr. tag ( ) . to_string ( ) ,
9692 )
9793 } ) ;
9894 for c in level {
99- done. insert ( c. tag ( ) . to_string ( ) ) ;
95+ done. insert ( c. tag ( ) ) ;
10096 }
10197 finished += level_len;
10298 }
103- unordered_queue
10499}
105100
106101/// Given some pending requests and a list of completed requests determine if
107102/// we have another request the we can process
108103fn get_next_benchmark_request < ' a > (
109104 pending : & ' a mut [ BenchmarkRequest ] ,
110- completed_set : & mut HashSet < String > ,
105+ completed_set : & HashSet < String > ,
111106) -> Option < & ' a BenchmarkRequest > {
112- sort_benchmark_requests ( completed_set, pending) . first ( )
107+ sort_benchmark_requests ( completed_set, pending) ;
108+ pending. first ( )
113109}
114110
115111/// Enqueue the job into the job_queue
0 commit comments