Skip to content

Commit 899a695

Browse files
committed
Introduce the "stable" benchmark category.
(Also, temporarily, the "primary-and-stable" category. All the current "primary-and-stable" benchmarks will become "stable" in the near future.) These categories are used in `perf-config.json` and the code that chooses which benchmarks to execute. They allow the `supports_stable` field to be removed. However, when it comes to storing the category in the database, to avoid database format changes, `Category` gets split into `supports_stable` (a bool) and `category` (either "primary" or "secondary"). Some notable details: - `Category` is moved to a different file, because it's no longer used by the DB code. - Some methods are moved from `BenchmarkConfig` to `Category`. - `Category` now derives `clap::ArgEnum`, which improves the `download` command's help message by listing the possible values.
1 parent 1d08022 commit 899a695

File tree

18 files changed

+115
-95
lines changed

18 files changed

+115
-95
lines changed

collector/benchmarks/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ The suite changes over time. Sometimes the code for a benchmark is updated, in
77
which case a small suffix will be added (starting with "-2", then "-3", and so
88
on.)
99

10-
There are two categories of benchmarks, **Primary** and **Secondary**.
10+
There are three categories of benchmarks, **Primary**, **Secondary**, and
11+
**Stable**.
1112

1213
## Primary
1314

@@ -120,3 +121,21 @@ compiler in interesting ways.
120121
- **wg-grammar**: A parser generator.
121122
[Stresses](https://github.com/rust-lang/rust/issues/58178) the borrow
122123
checker's implementation of NLL.
124+
125+
**Stable**
126+
127+
These are benchmarks used in the
128+
[dashboard](https://perf.rust-lang.org/dashboard.html). They provide the
129+
longest continuous data set for compiler performance. As a result, they are
130+
quite old (e.g. 2017 or earlier), and not necessarily reflective of typical
131+
Rust code being written today.
132+
133+
- **encoding**: See above.
134+
- **futures**: See above.
135+
- **html5ever**: See above.
136+
- **inflate**: See above.
137+
- **regex**: See above.
138+
- **piston-image**: See above.
139+
- **style-servo**: See above.
140+
- **syn**: See above.
141+
- **tokio-webpush-simple**: See above.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"supports_stable": true,
32
"touch_file": "src/lib.rs",
4-
"category": "primary"
3+
"category": "primary-and-stable"
54
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"supports_stable": true,
3-
"category": "primary"
2+
"category": "primary-and-stable"
43
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"supports_stable": true,
32
"touch_file": "src/lib.rs",
4-
"category": "primary"
3+
"category": "primary-and-stable"
54
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"supports_stable": true,
3-
"category": "primary"
2+
"category": "primary-and-stable"
43
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"supports_stable": false,
32
"touch_file": "src/lib.rs",
43
"category": "secondary"
54
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"supports_stable": true,
32
"runs": 1,
4-
"category": "primary"
3+
"category": "primary-and-stable"
54
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"supports_stable": true,
32
"touch_file": "src/lib.rs",
4-
"category": "primary"
3+
"category": "primary-and-stable"
54
}

collector/benchmarks/style-servo/perf-config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"cargo_rustc_opts": "--cap-lints=warn",
44
"cargo_toml": "components/style/Cargo.toml",
55
"runs": 1,
6-
"supports_stable": true,
76
"touch_file": "components/style/lib.rs",
8-
"category": "primary"
7+
"category": "primary-and-stable"
98
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"supports_stable": true,
32
"touch_file": "src/lib.rs",
4-
"category": "primary"
3+
"category": "primary-and-stable"
54
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"supports_stable": true,
32
"touch_file": "src/main.rs",
4-
"category": "primary"
3+
"category": "primary-and-stable"
54
}

collector/src/execute.rs

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use crate::{Compiler, Profile, Scenario};
44
use anyhow::{bail, Context};
55
use collector::command_output;
66
use collector::etw_parser;
7-
use database::{Category, PatchName, QueryLabel};
7+
use database::{PatchName, QueryLabel};
88
use futures::stream::FuturesUnordered;
99
use futures::stream::StreamExt;
10+
use serde::{Deserialize, Serialize};
1011
use std::collections::HashMap;
1112
use std::env;
1213
use std::fmt;
@@ -106,6 +107,57 @@ fn touch_all(path: &Path) -> anyhow::Result<()> {
106107
Ok(())
107108
}
108109

110+
#[derive(Debug, Clone, Copy, Serialize, Deserialize, clap::ArgEnum)]
111+
#[serde(rename_all = "kebab-case")]
112+
pub enum Category {
113+
Primary,
114+
Secondary,
115+
// FIXME: this should disappear after the 2022 benchmark overhaul is
116+
// complete.
117+
PrimaryAndStable,
118+
Stable,
119+
}
120+
121+
impl Category {
122+
pub fn has_stable(&self) -> bool {
123+
match self {
124+
Category::Primary | Category::Secondary => false,
125+
Category::PrimaryAndStable | Category::Stable => true,
126+
}
127+
}
128+
129+
pub fn is_primary_or_secondary(&self) -> bool {
130+
match self {
131+
Category::Primary | Category::Secondary | Category::PrimaryAndStable => true,
132+
Category::Stable => false,
133+
}
134+
}
135+
136+
// Within the DB, `Category` is represented in two fields:
137+
// - a `supports_stable` bool,
138+
// - a `category` which is either "primary" or "secondary".
139+
pub fn db_representation(&self) -> (bool, String) {
140+
match self {
141+
Category::Primary => (false, "primary".to_string()),
142+
Category::Secondary => (false, "secondary".to_string()),
143+
// These two have the same DB representation, even though they are
144+
// treated differently when choosing which benchmarks to run.
145+
Category::PrimaryAndStable | Category::Stable => (true, "primary".to_string()),
146+
}
147+
}
148+
}
149+
150+
impl fmt::Display for Category {
151+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
152+
match self {
153+
Category::Primary => f.write_str("primary"),
154+
Category::Secondary => f.write_str("secondary"),
155+
Category::PrimaryAndStable => f.write_str("primary-and-stable"),
156+
Category::Stable => f.write_str("stable"),
157+
}
158+
}
159+
}
160+
109161
fn default_runs() -> usize {
110162
3
111163
}
@@ -121,8 +173,6 @@ struct BenchmarkConfig {
121173
disabled: bool,
122174
#[serde(default = "default_runs")]
123175
runs: usize,
124-
#[serde(default)]
125-
supports_stable: bool,
126176

127177
/// The file that should be touched to ensure cargo re-checks the leaf crate
128178
/// we're interested in. Likely, something similar to `src/lib.rs`. The
@@ -1236,12 +1286,8 @@ impl Benchmark {
12361286
})
12371287
}
12381288

1239-
pub fn supports_stable(&self) -> bool {
1240-
self.config.supports_stable
1241-
}
1242-
1243-
pub fn category(&self) -> &Category {
1244-
&self.config.category
1289+
pub fn category(&self) -> Category {
1290+
self.config.category
12451291
}
12461292

12471293
#[cfg(windows)]

collector/src/main.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use anyhow::{bail, Context};
44
use clap::Parser;
5-
use database::{ArtifactId, Category, Commit};
5+
use database::{ArtifactId, Commit};
66
use log::debug;
77
use std::collections::HashSet;
88
use std::fs;
@@ -18,7 +18,7 @@ use tokio::runtime::Runtime;
1818
mod execute;
1919
mod sysroot;
2020

21-
use execute::{BenchProcessor, Benchmark, BenchmarkName, ProfileProcessor, Profiler};
21+
use execute::{BenchProcessor, Benchmark, BenchmarkName, Category, ProfileProcessor, Profiler};
2222
use sysroot::Sysroot;
2323

2424
#[derive(Debug, Copy, Clone)]
@@ -190,8 +190,7 @@ fn bench(
190190

191191
let mut measure_and_record =
192192
|benchmark_name: &BenchmarkName,
193-
benchmark_supports_stable: bool,
194-
benchmark_category: Category,
193+
category: Category,
195194
print_intro: &dyn Fn(),
196195
measure: &dyn Fn(&mut BenchProcessor) -> anyhow::Result<()>| {
197196
let is_fresh =
@@ -202,10 +201,11 @@ fn bench(
202201
return;
203202
}
204203
let mut tx = rt.block_on(conn.transaction());
204+
let (supports_stable, category) = category.db_representation();
205205
rt.block_on(tx.conn().record_benchmark(
206206
&benchmark_name.0,
207-
Some(benchmark_supports_stable),
208-
benchmark_category,
207+
Some(supports_stable),
208+
category,
209209
));
210210
print_intro();
211211

@@ -241,8 +241,7 @@ fn bench(
241241
for (nth_benchmark, benchmark) in benchmarks.iter().enumerate() {
242242
measure_and_record(
243243
&benchmark.name,
244-
benchmark.supports_stable(),
245-
benchmark.category().clone(),
244+
benchmark.category(),
246245
&|| {
247246
eprintln!(
248247
"{}",
@@ -257,7 +256,6 @@ fn bench(
257256
if bench_rustc {
258257
measure_and_record(
259258
&BenchmarkName("rustc".to_string()),
260-
/* supports_stable */ false,
261259
Category::Primary,
262260
&|| eprintln!("Special benchmark commencing (due to `--bench-rustc`)"),
263261
&|processor| processor.measure_rustc(compiler).context("measure rustc"),
@@ -860,12 +858,12 @@ struct DownloadCommand {
860858
#[clap(long, global = true)]
861859
name: Option<String>,
862860

863-
/// Overwrite the benchmark directory if it already exists.
861+
/// Overwrite the benchmark directory if it already exists
864862
#[clap(long, short('f'), global = true)]
865863
force: bool,
866864

867-
/// What category does the benchmark belong to (primary or secondary).
868-
#[clap(long, short('c'), global = true, default_value = "secondary")]
865+
/// What category does the benchmark belong to
866+
#[clap(long, short('c'), arg_enum, global = true, default_value = "secondary")]
869867
category: Category,
870868

871869
#[clap(subcommand)]
@@ -924,11 +922,12 @@ fn main_result() -> anyhow::Result<i32> {
924922
"",
925923
)?;
926924

927-
let benchmarks = get_benchmarks(
925+
let mut benchmarks = get_benchmarks(
928926
&benchmark_dir,
929927
local.include.as_deref(),
930928
local.exclude.as_deref(),
931929
)?;
930+
benchmarks.retain(|b| b.category().is_primary_or_secondary());
932931

933932
let res = bench(
934933
&mut rt,
@@ -978,11 +977,12 @@ fn main_result() -> anyhow::Result<i32> {
978977
let sysroot = Sysroot::install(commit.sha.to_string(), &target_triple)
979978
.with_context(|| format!("failed to install sysroot for {:?}", commit))?;
980979

981-
let benchmarks = get_benchmarks(
980+
let mut benchmarks = get_benchmarks(
982981
&benchmark_dir,
983982
next.include.as_deref(),
984983
next.exclude.as_deref(),
985984
)?;
985+
benchmarks.retain(|b| b.category().is_primary_or_secondary());
986986

987987
let res = bench(
988988
&mut rt,
@@ -1044,7 +1044,7 @@ fn main_result() -> anyhow::Result<i32> {
10441044

10451045
// Exclude benchmarks that don't work with a stable compiler.
10461046
let mut benchmarks = get_benchmarks(&benchmark_dir, None, None)?;
1047-
benchmarks.retain(|b| b.supports_stable());
1047+
benchmarks.retain(|b| b.category().has_stable());
10481048

10491049
let res = bench(
10501050
&mut rt,
@@ -1077,11 +1077,13 @@ fn main_result() -> anyhow::Result<i32> {
10771077
let profiles = Profile::expand_all(&local.profiles);
10781078
let scenarios = Scenario::expand_all(&local.scenarios);
10791079

1080-
let benchmarks = get_benchmarks(
1080+
let mut benchmarks = get_benchmarks(
10811081
&benchmark_dir,
10821082
local.include.as_deref(),
10831083
local.exclude.as_deref(),
10841084
)?;
1085+
benchmarks.retain(|b| b.category().is_primary_or_secondary());
1086+
10851087
let mut errors = BenchmarkErrors::new();
10861088

10871089
let mut get_toolchain_and_profile =

database/src/lib.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -767,38 +767,6 @@ impl fmt::Display for CollectionId {
767767
#[derive(Debug, Clone, Serialize)]
768768
pub struct BenchmarkData {
769769
pub name: String,
770-
pub category: Category,
770+
pub category: String,
771771
}
772772

773-
#[derive(Debug, Clone, Serialize, Deserialize)]
774-
#[serde(rename_all = "lowercase")]
775-
pub enum Category {
776-
Primary,
777-
Secondary,
778-
}
779-
780-
impl Default for Category {
781-
fn default() -> Self {
782-
Self::Secondary
783-
}
784-
}
785-
786-
impl fmt::Display for Category {
787-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
788-
match self {
789-
Category::Primary => f.write_str("primary"),
790-
Category::Secondary => f.write_str("secondary"),
791-
}
792-
}
793-
}
794-
impl std::str::FromStr for Category {
795-
type Err = anyhow::Error;
796-
797-
fn from_str(input: &str) -> Result<Self, Self::Err> {
798-
match input {
799-
"primary" => Ok(Category::Primary),
800-
"secondary" => Ok(Category::Secondary),
801-
_ => Err(anyhow::anyhow!("Invalid category {input}")),
802-
}
803-
}
804-
}

database/src/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{ArtifactId, ArtifactIdNumber, BenchmarkData, Category};
1+
use crate::{ArtifactId, ArtifactIdNumber, BenchmarkData};
22
use crate::{CollectionId, Index, Profile, QueryDatum, QueuedCommit, Scenario, Step};
33
use chrono::{DateTime, Utc};
44
use hashbrown::HashMap;
@@ -31,7 +31,7 @@ pub trait Connection: Send + Sync {
3131
&self,
3232
krate: &str,
3333
supports_stable: Option<bool>,
34-
category: Category,
34+
category: String,
3535
);
3636
async fn record_statistic(
3737
&self,

0 commit comments

Comments
 (0)