Skip to content

Commit abcff71

Browse files
committed
Significantly speed up assembling of sysroots
By avoiding some redundant rustc calls and stripping debuginfo for wrappers. ./y.rs build --sysroot none now runs 44% faster. Benchmark 1: ./y_before.bin build --sysroot none Time (mean ± σ): 2.200 s ± 0.038 s [User: 2.140 s, System: 0.653 s] Range (min … max): 2.171 s … 2.303 s 10 runs Benchmark 2: ./y_after.bin build --sysroot none Time (mean ± σ): 1.528 s ± 0.020 s [User: 1.388 s, System: 0.490 s] Range (min … max): 1.508 s … 1.580 s 10 runs Summary './y_after.bin build --sysroot none' ran 1.44 ± 0.03 times faster than './y_before.bin build --sysroot none'
1 parent 1319732 commit abcff71

File tree

4 files changed

+25
-35
lines changed

4 files changed

+25
-35
lines changed

build_system/bench.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::path::Path;
44

55
use super::path::{Dirs, RelPath};
66
use super::prepare::GitRepo;
7-
use super::rustc_info::{get_file_name, get_wrapper_file_name};
7+
use super::rustc_info::get_file_name;
88
use super::utils::{hyperfine_command, is_ci, spawn_and_wait, CargoProject, Compiler};
99

1010
pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
@@ -51,7 +51,8 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
5151
.unwrap();
5252

5353
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
54-
let cargo_clif = RelPath::DIST.to_path(dirs).join(get_wrapper_file_name("cargo-clif", "bin"));
54+
let cargo_clif =
55+
RelPath::DIST.to_path(dirs).join(get_file_name("cargo_clif", "bin").replace('_', "-"));
5556
let manifest_path = SIMPLE_RAYTRACER.manifest_path(dirs);
5657
let target_dir = SIMPLE_RAYTRACER.target_dir(dirs);
5758

build_system/build_sysroot.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use std::path::{Path, PathBuf};
33
use std::process::{self, Command};
44

55
use super::path::{Dirs, RelPath};
6-
use super::rustc_info::{
7-
get_file_name, get_rustc_version, get_toolchain_name, get_wrapper_file_name,
8-
};
6+
use super::rustc_info::{get_cargo_path, get_file_name, get_rustc_version, get_toolchain_name};
97
use super::utils::{spawn_and_wait, try_hard_link, CargoProject, Compiler};
108
use super::SysrootKind;
119

@@ -42,16 +40,17 @@ pub(crate) fn build_sysroot(
4240
try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path);
4341

4442
// Build and copy rustc and cargo wrappers
43+
let wrapper_base_name = get_file_name("____", "bin");
4544
for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] {
46-
let wrapper_name = get_wrapper_file_name(wrapper, "bin");
45+
let wrapper_name = wrapper_base_name.replace("____", wrapper);
4746

4847
let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc);
4948
build_cargo_wrapper_cmd
5049
.env("TOOLCHAIN_NAME", get_toolchain_name())
5150
.arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs")))
5251
.arg("-o")
5352
.arg(DIST_DIR.to_path(dirs).join(wrapper_name))
54-
.arg("-g");
53+
.arg("-Cstrip=debuginfo");
5554
spawn_and_wait(build_cargo_wrapper_cmd);
5655
}
5756

@@ -89,7 +88,23 @@ pub(crate) fn build_sysroot(
8988
}
9089
}
9190

92-
let mut target_compiler = Compiler::clif_with_triple(&dirs, target_triple);
91+
let mut target_compiler = {
92+
let dirs: &Dirs = &dirs;
93+
let rustc_clif =
94+
RelPath::DIST.to_path(&dirs).join(wrapper_base_name.replace("____", "rustc-clif"));
95+
let rustdoc_clif =
96+
RelPath::DIST.to_path(&dirs).join(wrapper_base_name.replace("____", "rustdoc-clif"));
97+
98+
Compiler {
99+
cargo: get_cargo_path(),
100+
rustc: rustc_clif.clone(),
101+
rustdoc: rustdoc_clif.clone(),
102+
rustflags: String::new(),
103+
rustdocflags: String::new(),
104+
triple: target_triple,
105+
runner: vec![],
106+
}
107+
};
93108
if !is_native {
94109
target_compiler.set_cross_linker_and_runner();
95110
}

build_system/rustc_info.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,3 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String {
9393
assert!(file_name.contains(crate_name));
9494
file_name
9595
}
96-
97-
/// Similar to `get_file_name`, but converts any dashes (`-`) in the `crate_name` to
98-
/// underscores (`_`). This is specially made for the rustc and cargo wrappers
99-
/// which have a dash in the name, and that is not allowed in a crate name.
100-
pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str) -> String {
101-
let crate_name = crate_name.replace('-', "_");
102-
let wrapper_name = get_file_name(&crate_name, crate_type);
103-
wrapper_name.replace('_', "-")
104-
}

build_system/utils.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
55
use std::process::{self, Command, Stdio};
66

77
use super::path::{Dirs, RelPath};
8-
use super::rustc_info::{get_cargo_path, get_rustc_path, get_rustdoc_path, get_wrapper_file_name};
8+
use super::rustc_info::{get_cargo_path, get_rustc_path, get_rustdoc_path};
99

1010
#[derive(Clone, Debug)]
1111
pub(crate) struct Compiler {
@@ -31,23 +31,6 @@ impl Compiler {
3131
}
3232
}
3333

34-
pub(crate) fn clif_with_triple(dirs: &Dirs, triple: String) -> Compiler {
35-
let rustc_clif =
36-
RelPath::DIST.to_path(&dirs).join(get_wrapper_file_name("rustc-clif", "bin"));
37-
let rustdoc_clif =
38-
RelPath::DIST.to_path(&dirs).join(get_wrapper_file_name("rustdoc-clif", "bin"));
39-
40-
Compiler {
41-
cargo: get_cargo_path(),
42-
rustc: rustc_clif.clone(),
43-
rustdoc: rustdoc_clif.clone(),
44-
rustflags: String::new(),
45-
rustdocflags: String::new(),
46-
triple,
47-
runner: vec![],
48-
}
49-
}
50-
5134
pub(crate) fn set_cross_linker_and_runner(&mut self) {
5235
match self.triple.as_str() {
5336
"aarch64-unknown-linux-gnu" => {

0 commit comments

Comments
 (0)