Skip to content

Commit 336fca3

Browse files
bootstrap: at most one rustc running simultaneously
This commit adds another variance reduction strategy to rustc execution as part of the bootstrap process, namely, rustbuild is configured to launch at most one rustc (-j1) but then the individual rustc's are configured to have access to full parallelism. This is not very realistic -- the build overall will likely be slower than it could have been, when rustcs fight for resources -- but it should hopefully still be representative of the total amount of work that needs to be done for each rustc. We care relatively speaking much more about being deterministic rather than representative of "true" workloads, though, at least for now. It is relatively unlikely that most improvements in build times will be major (>20%, which is roughly the variance we observe today).
1 parent 53a9602 commit 336fca3

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

collector/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ path = "src/main.rs"
3737
[[bin]]
3838
name = "rustc-fake"
3939
path = "src/rustc-fake.rs"
40+
41+
[[bin]]
42+
name = "bootstrap-rustc"
43+
path = "src/bootstrap-rustc.rs"

collector/src/bootstrap-rustc.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use jobserver::Client;
2+
use std::env;
3+
use std::process::Command;
4+
5+
fn run() -> i32 {
6+
let server = Client::new(num_cpus::get()).expect("made jobserver");
7+
8+
let mut cmd = Command::new(env::var_os("RUSTC_PERF_REAL_RUSTC").unwrap());
9+
cmd.args(env::args_os());
10+
11+
// We want the bootstrap rustc to have access to full parallelism, even
12+
// though the parent cargo is permitted to spawn at most one rustc (-j1).
13+
server.configure(&mut cmd);
14+
15+
let status = cmd.status().expect("spawned");
16+
17+
if status.success() {
18+
return 0;
19+
} else {
20+
return 1;
21+
}
22+
}
23+
24+
fn main() {
25+
std::process::exit(run());
26+
}

collector/src/execute/rustc.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
use crate::Compiler;
1111
use anyhow::Context;
12+
use std::env;
1213
use std::{collections::HashMap, process::Command};
1314
use std::{path::Path, time::Duration};
1415
use tokio::runtime::Runtime;
@@ -54,6 +55,10 @@ fn record(
5455
.context("git clean -fxd")?;
5556
assert!(status.success(), "git clean -fxd successful");
5657

58+
let mut fake_rustc = env::current_exe().unwrap();
59+
fake_rustc.pop();
60+
fake_rustc.push("bootstrap-rustc");
61+
5762
// Configure the compiler we're given as the one to use.
5863
let status = Command::new(
5964
checkout
@@ -67,7 +72,8 @@ fn record(
6772
.arg("--set")
6873
.arg("build.print-step-timings=true")
6974
.arg("--set")
70-
.arg(&format!("build.rustc={}", compiler.rustc.to_str().unwrap()))
75+
.arg(&format!("build.rustc={}", fake_rustc.to_str().unwrap()))
76+
.env("RUSTC_PERF_REAL_RUSTC", &compiler.rustc)
7177
.arg("--set")
7278
.arg(&format!("build.cargo={}", compiler.cargo.to_str().unwrap()))
7379
.status()
@@ -85,6 +91,11 @@ fn record(
8591
.arg("build")
8692
.arg("--stage")
8793
.arg("0")
94+
// We want bootstrap and the Cargos it spawns to have no parallelism --
95+
// if multiple rustcs are competing for jobserver tokens, we introduce
96+
// quite a bit of variance. Instead, we configure -j1 here, and then
97+
// full all vCPU parallelism for each rustc.
98+
.arg("-j1")
8899
.arg("compiler/rustc"),
89100
)
90101
.context("building rustc")?;

0 commit comments

Comments
 (0)