|
| 1 | +//! This module serves for defining the benchmark sets that are used by individual collectors. |
| 2 | +//! Each benchmark set is identified by a pair (target, ID); each target has a specific number |
| 3 | +//! of IDs. |
| 4 | +//! The union of all benchmark sets for a given target should represent all the benchmarks that |
| 5 | +//! should be executed on a master/try artifact. |
| 6 | +//! Release artifacts do not participate in the benchmark set splitting and are always executed |
| 7 | +//! on a single collector per target. |
| 8 | +
|
| 9 | +mod compile_benchmarks; |
| 10 | + |
| 11 | +use crate::compile::benchmark::target::Target; |
| 12 | +use crate::compile::benchmark::BenchmarkName; |
| 13 | + |
| 14 | +/// Represents a single set of master/try benchmarks. |
| 15 | +#[derive(Debug)] |
| 16 | +pub struct BenchmarkSetId { |
| 17 | + target: Target, |
| 18 | + index: u32, |
| 19 | +} |
| 20 | + |
| 21 | +impl BenchmarkSetId { |
| 22 | + pub fn new(target: Target, index: u32) -> Self { |
| 23 | + Self { target, index } |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +/// Represents a subset of benchmarks that should be benchmarked by a single collector. |
| 28 | +#[derive(Debug, PartialEq, Eq, Hash)] |
| 29 | +pub enum BenchmarkSetMember { |
| 30 | + /// Benchmark a specific compile-time benchmark |
| 31 | + CompileBenchmark(BenchmarkName), |
| 32 | + /// Benchmark *all* the runtime benchmarks. |
| 33 | + /// For simplicity, we currently always benchmark all of them on a single collector. |
| 34 | + RuntimeBenchmarks, |
| 35 | + /// Benchmark the rustc bootstrap |
| 36 | + Rustc, |
| 37 | +} |
| 38 | + |
| 39 | +/// Return the number of benchmark sets for the given target. |
| 40 | +pub fn benchmark_set_count(target: Target) -> usize { |
| 41 | + match target { |
| 42 | + Target::X86_64UnknownLinuxGnu => 1, |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +/// Expand all the benchmarks that should be performed by a single collector. |
| 47 | +pub fn expand_benchmark_set(id: BenchmarkSetId) -> Vec<BenchmarkSetMember> { |
| 48 | + use compile_benchmarks::*; |
| 49 | + |
| 50 | + match (id.target, id.index) { |
| 51 | + (Target::X86_64UnknownLinuxGnu, 0) => { |
| 52 | + vec![ |
| 53 | + compile(AWAIT_CALL_TREE), |
| 54 | + compile(BITMAPS_3_2_1), |
| 55 | + compile(BITMAPS_3_2_1_NEW_SOLVER), |
| 56 | + compile(CARGO_0_87_1), |
| 57 | + compile(CLAP_DERIVE_4_5_32), |
| 58 | + compile(COERCIONS), |
| 59 | + compile(CRANELIFT_CODEGEN_0_119_0), |
| 60 | + compile(CTFE_STRESS_5), |
| 61 | + compile(DEEP_VECTOR), |
| 62 | + compile(DEEPLY_NESTED_MULTI), |
| 63 | + compile(DERIVE), |
| 64 | + compile(DIESEL_2_2_10), |
| 65 | + compile(EXTERNS), |
| 66 | + compile(EZA_0_21_2), |
| 67 | + compile(HELLOWORLD), |
| 68 | + compile(HELLOWORLD_TINY), |
| 69 | + compile(HTML5EVER_0_31_0), |
| 70 | + compile(HTML5EVER_0_31_0_NEW_SOLVER), |
| 71 | + compile(HYPER_1_6_0), |
| 72 | + compile(IMAGE_0_25_6), |
| 73 | + compile(INCLUDE_BLOB), |
| 74 | + compile(ISSUE_46449), |
| 75 | + compile(ISSUE_58319), |
| 76 | + compile(ISSUE_88862), |
| 77 | + compile(LARGE_WORKSPACE), |
| 78 | + compile(LIBC_0_2_172), |
| 79 | + compile(MANY_ASSOC_ITEMS), |
| 80 | + compile(MATCH_STRESS), |
| 81 | + compile(NALGEBRA_0_33_0), |
| 82 | + compile(NALGEBRA_0_33_0_NEW_SOLVER), |
| 83 | + compile(PROJECTION_CACHING), |
| 84 | + compile(REGEX_AUTOMATA_0_4_8), |
| 85 | + compile(REGRESSION_31157), |
| 86 | + compile(RIPGREP_14_1_1), |
| 87 | + compile(RIPGREP_14_1_1_TINY), |
| 88 | + compile(SERDE_1_0_219), |
| 89 | + compile(SERDE_1_0_219_NEW_SOLVER), |
| 90 | + compile(SERDE_1_0_219_THREADS4), |
| 91 | + compile(SERDE_DERIVE_1_0_219), |
| 92 | + compile(STM32F4_0_15_1), |
| 93 | + compile(SYN_2_0_101), |
| 94 | + compile(SYN_2_0_101_NEW_SOLVER), |
| 95 | + compile(TOKEN_STREAM_STRESS), |
| 96 | + compile(TT_MUNCHER), |
| 97 | + compile(TUPLE_STRESS), |
| 98 | + compile(TYPENUM_1_18_0), |
| 99 | + compile(UCD), |
| 100 | + compile(UNICODE_NORMALIZATION_0_1_24), |
| 101 | + compile(UNIFY_LINEARLY), |
| 102 | + compile(UNUSED_WARNINGS), |
| 103 | + compile(WF_PROJECTION_STRESS_65510), |
| 104 | + compile(WG_GRAMMAR), |
| 105 | + BenchmarkSetMember::Rustc, |
| 106 | + BenchmarkSetMember::RuntimeBenchmarks, |
| 107 | + ] |
| 108 | + } |
| 109 | + (Target::X86_64UnknownLinuxGnu, 1..) => { |
| 110 | + panic!("Unknown benchmark set id {id:?}"); |
| 111 | + } |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +/// Helper function for creating compile-time benchmark member sets. |
| 116 | +fn compile(name: &str) -> BenchmarkSetMember { |
| 117 | + BenchmarkSetMember::CompileBenchmark(BenchmarkName::from(name)) |
| 118 | +} |
| 119 | + |
| 120 | +#[cfg(test)] |
| 121 | +mod tests { |
| 122 | + use crate::benchmark_set::{ |
| 123 | + benchmark_set_count, expand_benchmark_set, BenchmarkSetId, BenchmarkSetMember, |
| 124 | + }; |
| 125 | + use crate::compile::benchmark::target::Target; |
| 126 | + use crate::compile::benchmark::{ |
| 127 | + get_compile_benchmarks, BenchmarkName, CompileBenchmarkFilter, |
| 128 | + }; |
| 129 | + use std::collections::HashSet; |
| 130 | + use std::path::Path; |
| 131 | + |
| 132 | + /// Sanity check for making sure that the expanded benchmark sets are non-overlapping and |
| 133 | + /// complete, i.e. they don't miss any benchmarks. |
| 134 | + #[test] |
| 135 | + fn check_benchmark_set_x64() { |
| 136 | + let target = Target::X86_64UnknownLinuxGnu; |
| 137 | + let sets = (0..benchmark_set_count(target)) |
| 138 | + .map(|index| { |
| 139 | + expand_benchmark_set(BenchmarkSetId { |
| 140 | + target, |
| 141 | + index: index as u32, |
| 142 | + }) |
| 143 | + }) |
| 144 | + .collect::<Vec<Vec<BenchmarkSetMember>>>(); |
| 145 | + |
| 146 | + // Assert set is unique |
| 147 | + for set in &sets { |
| 148 | + let hashset = set.iter().collect::<HashSet<_>>(); |
| 149 | + assert_eq!( |
| 150 | + set.len(), |
| 151 | + hashset.len(), |
| 152 | + "Benchmark set {set:?} contains duplicates" |
| 153 | + ); |
| 154 | + } |
| 155 | + |
| 156 | + // Go through all unique pairs of sets and assert that they don't overlap |
| 157 | + for i in 0..sets.len() { |
| 158 | + for j in i + 1..sets.len() { |
| 159 | + let set_a = &sets[i]; |
| 160 | + let set_b = &sets[j]; |
| 161 | + let hashset_a = set_a.iter().collect::<HashSet<_>>(); |
| 162 | + let hashset_b = set_b.iter().collect::<HashSet<_>>(); |
| 163 | + assert!( |
| 164 | + hashset_a.is_disjoint(&hashset_b), |
| 165 | + "Benchmark sets {set_a:?} and {set_b:?} overlap" |
| 166 | + ); |
| 167 | + } |
| 168 | + } |
| 169 | + |
| 170 | + // Check that the union of all sets contains all the required benchmarks |
| 171 | + let all_members = sets.iter().flatten().collect::<HashSet<_>>(); |
| 172 | + assert!(all_members.contains(&BenchmarkSetMember::Rustc)); |
| 173 | + assert!(all_members.contains(&BenchmarkSetMember::RuntimeBenchmarks)); |
| 174 | + |
| 175 | + const BENCHMARK_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/compile-benchmarks"); |
| 176 | + let all_compile_benchmarks = |
| 177 | + get_compile_benchmarks(Path::new(BENCHMARK_DIR), CompileBenchmarkFilter::All) |
| 178 | + .unwrap() |
| 179 | + .into_iter() |
| 180 | + .filter(|b| !b.category().is_stable()) |
| 181 | + .map(|b| b.name) |
| 182 | + .collect::<Vec<BenchmarkName>>(); |
| 183 | + for benchmark in &all_compile_benchmarks { |
| 184 | + assert!( |
| 185 | + all_members.contains(&BenchmarkSetMember::CompileBenchmark(benchmark.clone())), |
| 186 | + "Compile-time benchmark `{benchmark}` is missing in the union of all sets" |
| 187 | + ); |
| 188 | + } |
| 189 | + for benchmark in &all_members { |
| 190 | + if let BenchmarkSetMember::CompileBenchmark(name) = benchmark { |
| 191 | + assert!( |
| 192 | + all_compile_benchmarks.contains(name), |
| 193 | + "Compile-time benchmark {name} does not exist on disk or is a stable benchmark" |
| 194 | + ); |
| 195 | + } |
| 196 | + } |
| 197 | + assert_eq!(all_members.len(), all_compile_benchmarks.len() + 2); |
| 198 | + } |
| 199 | +} |
0 commit comments