]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #83152 - guswynn:jemallocator_part2, r=Mark-Simulacrum
authorbors <bors@rust-lang.org>
Mon, 5 Apr 2021 21:14:27 +0000 (21:14 +0000)
committerbors <bors@rust-lang.org>
Mon, 5 Apr 2021 21:14:27 +0000 (21:14 +0000)
Use tikv-jemallocator in rustc/rustdoc in addition to jemalloc-sys when enabled.

In https://github.com/rust-lang/rust/pull/81782 it was mentioned that one reason rustc may benefit from minimalloc is it doesn't use the `sdallocx` api from jemalloc.

Currently, on unix, rust uses jemalloc by importing its symbols to use them with the default, System (libc) global allocator.
This PR switches its global alloc to `tikv-jemallocator`, which correctly uses sized deallocation (https://docs.rs/tikv-jemallocator/0.4.1/src/tikv_jemallocator/lib.rs.html#121-126). `tikv-jemallocator`, as far as I can tell, is a more up-to-date set of bindings to jemalloc than `jemallocator`

The perf results of this pr are in large part due to the version upgrade of jemalloc, but sized deallocation has a non-trivial improvement, particularly to rustdoc.

This pr also includes changes to bootstrap to correctly pass the jemalloc feature through to the rustdoc build

1  2 
src/bootstrap/tool.rs

diff --combined src/bootstrap/tool.rs
index f9be35d7c5e0df7619acb4feda3793a239c67f3f,c2b8bd71e000ccaba2c7af473c5ec8245df433c2..e85f4628fb03a95727e316a67983ae7ba5f6b415
@@@ -513,25 -513,17 +513,30 @@@ impl Step for Rustdoc 
          // rustc compiler it's paired with, so it must be built with the previous stage compiler.
          let build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build);
  
 +        // When using `download-rustc` and a stage0 build_compiler, copying rustc doesn't actually
 +        // build stage0 libstd (because the libstd in sysroot has the wrong ABI). Explicitly build
 +        // it.
 +        builder.ensure(compile::Std { compiler: build_compiler, target: target_compiler.host });
 +        builder.ensure(compile::Rustc { compiler: build_compiler, target: target_compiler.host });
 +        // NOTE: this implies that `download-rustc` is pretty useless when compiling with the stage0
 +        // compiler, since you do just as much work.
 +        if !builder.config.dry_run && builder.config.download_rustc && build_compiler.stage == 0 {
 +            println!(
 +                "warning: `download-rustc` does nothing when building stage1 tools; consider using `--stage 2` instead"
 +            );
 +        }
 +
          // The presence of `target_compiler` ensures that the necessary libraries (codegen backends,
          // compiler libraries, ...) are built. Rustdoc does not require the presence of any
          // libraries within sysroot_libdir (i.e., rustlib), though doctests may want it (since
          // they'll be linked to those libraries). As such, don't explicitly `ensure` any additional
          // libraries here. The intuition here is that If we've built a compiler, we should be able
          // to build rustdoc.
+         //
+         let mut features = Vec::new();
+         if builder.config.jemalloc {
+             features.push("jemalloc".to_string());
+         }
  
          let cargo = prepare_tool_cargo(
              builder,
              "build",
              "src/tools/rustdoc",
              SourceType::InTree,
-             &[],
+             features.as_slice(),
          );
  
          builder.info(&format!(