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'
This commit is contained in:
bjorn3 2023-01-15 14:14:13 +00:00
parent 13197322ec
commit abcff71bec
4 changed files with 25 additions and 35 deletions

View File

@ -4,7 +4,7 @@
use super::path::{Dirs, RelPath}; use super::path::{Dirs, RelPath};
use super::prepare::GitRepo; use super::prepare::GitRepo;
use super::rustc_info::{get_file_name, get_wrapper_file_name}; use super::rustc_info::get_file_name;
use super::utils::{hyperfine_command, is_ci, spawn_and_wait, CargoProject, Compiler}; use super::utils::{hyperfine_command, is_ci, spawn_and_wait, CargoProject, Compiler};
pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github( pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
@ -51,7 +51,8 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
.unwrap(); .unwrap();
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer"); eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
let cargo_clif = RelPath::DIST.to_path(dirs).join(get_wrapper_file_name("cargo-clif", "bin")); let cargo_clif =
RelPath::DIST.to_path(dirs).join(get_file_name("cargo_clif", "bin").replace('_', "-"));
let manifest_path = SIMPLE_RAYTRACER.manifest_path(dirs); let manifest_path = SIMPLE_RAYTRACER.manifest_path(dirs);
let target_dir = SIMPLE_RAYTRACER.target_dir(dirs); let target_dir = SIMPLE_RAYTRACER.target_dir(dirs);

View File

@ -3,9 +3,7 @@
use std::process::{self, Command}; use std::process::{self, Command};
use super::path::{Dirs, RelPath}; use super::path::{Dirs, RelPath};
use super::rustc_info::{ use super::rustc_info::{get_cargo_path, get_file_name, get_rustc_version, get_toolchain_name};
get_file_name, get_rustc_version, get_toolchain_name, get_wrapper_file_name,
};
use super::utils::{spawn_and_wait, try_hard_link, CargoProject, Compiler}; use super::utils::{spawn_and_wait, try_hard_link, CargoProject, Compiler};
use super::SysrootKind; use super::SysrootKind;
@ -42,8 +40,9 @@ pub(crate) fn build_sysroot(
try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path); try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path);
// Build and copy rustc and cargo wrappers // Build and copy rustc and cargo wrappers
let wrapper_base_name = get_file_name("____", "bin");
for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] { for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] {
let wrapper_name = get_wrapper_file_name(wrapper, "bin"); let wrapper_name = wrapper_base_name.replace("____", wrapper);
let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc); let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc);
build_cargo_wrapper_cmd build_cargo_wrapper_cmd
@ -51,7 +50,7 @@ pub(crate) fn build_sysroot(
.arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs"))) .arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs")))
.arg("-o") .arg("-o")
.arg(DIST_DIR.to_path(dirs).join(wrapper_name)) .arg(DIST_DIR.to_path(dirs).join(wrapper_name))
.arg("-g"); .arg("-Cstrip=debuginfo");
spawn_and_wait(build_cargo_wrapper_cmd); spawn_and_wait(build_cargo_wrapper_cmd);
} }
@ -89,7 +88,23 @@ pub(crate) fn build_sysroot(
} }
} }
let mut target_compiler = Compiler::clif_with_triple(&dirs, target_triple); let mut target_compiler = {
let dirs: &Dirs = &dirs;
let rustc_clif =
RelPath::DIST.to_path(&dirs).join(wrapper_base_name.replace("____", "rustc-clif"));
let rustdoc_clif =
RelPath::DIST.to_path(&dirs).join(wrapper_base_name.replace("____", "rustdoc-clif"));
Compiler {
cargo: get_cargo_path(),
rustc: rustc_clif.clone(),
rustdoc: rustdoc_clif.clone(),
rustflags: String::new(),
rustdocflags: String::new(),
triple: target_triple,
runner: vec![],
}
};
if !is_native { if !is_native {
target_compiler.set_cross_linker_and_runner(); target_compiler.set_cross_linker_and_runner();
} }

View File

@ -93,12 +93,3 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String {
assert!(file_name.contains(crate_name)); assert!(file_name.contains(crate_name));
file_name file_name
} }
/// Similar to `get_file_name`, but converts any dashes (`-`) in the `crate_name` to
/// underscores (`_`). This is specially made for the rustc and cargo wrappers
/// which have a dash in the name, and that is not allowed in a crate name.
pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str) -> String {
let crate_name = crate_name.replace('-', "_");
let wrapper_name = get_file_name(&crate_name, crate_type);
wrapper_name.replace('_', "-")
}

View File

@ -5,7 +5,7 @@
use std::process::{self, Command, Stdio}; use std::process::{self, Command, Stdio};
use super::path::{Dirs, RelPath}; use super::path::{Dirs, RelPath};
use super::rustc_info::{get_cargo_path, get_rustc_path, get_rustdoc_path, get_wrapper_file_name}; use super::rustc_info::{get_cargo_path, get_rustc_path, get_rustdoc_path};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct Compiler { pub(crate) struct Compiler {
@ -31,23 +31,6 @@ pub(crate) fn bootstrap_with_triple(triple: String) -> Compiler {
} }
} }
pub(crate) fn clif_with_triple(dirs: &Dirs, triple: String) -> Compiler {
let rustc_clif =
RelPath::DIST.to_path(&dirs).join(get_wrapper_file_name("rustc-clif", "bin"));
let rustdoc_clif =
RelPath::DIST.to_path(&dirs).join(get_wrapper_file_name("rustdoc-clif", "bin"));
Compiler {
cargo: get_cargo_path(),
rustc: rustc_clif.clone(),
rustdoc: rustdoc_clif.clone(),
rustflags: String::new(),
rustdocflags: String::new(),
triple,
runner: vec![],
}
}
pub(crate) fn set_cross_linker_and_runner(&mut self) { pub(crate) fn set_cross_linker_and_runner(&mut self) {
match self.triple.as_str() { match self.triple.as_str() {
"aarch64-unknown-linux-gnu" => { "aarch64-unknown-linux-gnu" => {