Skip to content

Commit 908a5d3

Browse files
committed
Use mimalloc as the global allocator on x86_64-pc-windows-msvc
1 parent 11c97bb commit 908a5d3

10 files changed

Lines changed: 38 additions & 8 deletions

File tree

Cargo.lock

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ checksum = "af491d569909a7e4dee0ad7db7f5341fef5c614d5b8ec8cf765732aba3cff681"
756756
dependencies = [
757757
"serde",
758758
"termcolor",
759-
"unicode-width 0.1.14",
759+
"unicode-width 0.2.2",
760760
]
761761

762762
[[package]]
@@ -2216,6 +2216,15 @@ version = "0.2.15"
22162216
source = "registry+https://github.com/rust-lang/crates.io-index"
22172217
checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
22182218

2219+
[[package]]
2220+
name = "libmimalloc-sys"
2221+
version = "0.1.46"
2222+
source = "registry+https://github.com/rust-lang/crates.io-index"
2223+
checksum = "bc89deee4af0429081d2a518c0431ae068222a5a262a3bc6ff4d8535ec2e02fe"
2224+
dependencies = [
2225+
"cc",
2226+
]
2227+
22192228
[[package]]
22202229
name = "libredox"
22212230
version = "0.1.10"
@@ -2399,6 +2408,15 @@ dependencies = [
23992408
"libc",
24002409
]
24012410

2411+
[[package]]
2412+
name = "mimalloc"
2413+
version = "0.1.49"
2414+
source = "registry+https://github.com/rust-lang/crates.io-index"
2415+
checksum = "aca3c01a711f395b4257b81674c0e90e8dd1f1e62c4b7db45f684cc7a4fcb18a"
2416+
dependencies = [
2417+
"libmimalloc-sys",
2418+
]
2419+
24022420
[[package]]
24032421
name = "minifier"
24042422
version = "0.3.6"
@@ -3808,6 +3826,7 @@ dependencies = [
38083826
"ctrlc",
38093827
"jiff",
38103828
"libc",
3829+
"mimalloc",
38113830
"rustc_abi",
38123831
"rustc_ast",
38133832
"rustc_ast_pretty",

compiler/rustc/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ rustc_public_bridge = { path = "../rustc_public_bridge" }
2626
getrandom = "=0.3.3"
2727
wasi = "=0.14.2"
2828

29-
30-
[dependencies.tikv-jemalloc-sys]
29+
[target.'cfg(not(target_os = "windows"))'.dependencies.tikv-jemalloc-sys]
3130
version = "0.6.1"
3231
optional = true
3332
features = ['override_allocator_on_supported_platforms']
@@ -39,7 +38,7 @@ llvm = ['rustc_driver_impl/llvm']
3938
llvm_enzyme = ['rustc_driver_impl/llvm_enzyme']
4039
llvm_offload = ['rustc_driver_impl/llvm_offload']
4140
max_level_info = ['rustc_driver_impl/max_level_info']
42-
override_allocator = ['dep:tikv-jemalloc-sys']
41+
override_allocator = ['dep:tikv-jemalloc-sys', 'rustc_driver_impl/override_allocator']
4342
rustc_randomized_layouts = ['rustc_driver_impl/rustc_randomized_layouts']
4443
# tidy-alphabetical-end
4544

compiler/rustc/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use std::process::ExitCode;
3737
// to compare their performance, see
3838
// https://github.com/rust-lang/rust/commit/b90cfc887c31c3e7a9e6d462e2464db1fe506175#diff-43914724af6e464c1da2171e4a9b6c7e607d5bc1203fa95c0ab85be4122605ef
3939
// for an example of how to do so.
40-
#[cfg(feature = "override_allocator")]
40+
#[cfg(all(feature = "override_allocator", not(target_os = "windows")))]
4141
use tikv_jemalloc_sys as _;
4242

4343
fn main() -> ExitCode {

compiler/rustc_driver_impl/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,18 @@ features = [
5555
ctrlc = "3.4.4"
5656
# tidy-alphabetical-end
5757

58+
[target.'cfg(target_os = "windows")'.dependencies.mimalloc]
59+
version = "0.1.49"
60+
optional = true
61+
5862
[features]
5963
# tidy-alphabetical-start
6064
check_only = ['rustc_interface/check_only']
6165
llvm = ['rustc_interface/llvm']
6266
llvm_enzyme = ['rustc_interface/llvm_enzyme']
6367
llvm_offload = ['rustc_interface/llvm_offload']
6468
max_level_info = ['rustc_log/max_level_info']
69+
override_allocator = ['dep:mimalloc']
6570
rustc_randomized_layouts = [
6671
'rustc_index/rustc_randomized_layouts',
6772
'rustc_middle/rustc_randomized_layouts'

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ use rustc_target::json::ToJson;
6363
use rustc_target::spec::{Target, TargetTuple};
6464
use tracing::trace;
6565

66+
#[cfg(all(feature = "override_allocator", target_os = "windows"))]
67+
#[global_allocator]
68+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
69+
6670
#[allow(unused_macros)]
6771
macro do_not_use_print($($t:tt)*) {
6872
std::compile_error!(

src/ci/github-actions/jobs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ auto:
659659
--target=x86_64-pc-windows-msvc
660660
--enable-full-tools
661661
--enable-profiler
662+
--set rust.override-allocator
662663
--set rust.codegen-units=1
663664
SCRIPT: python x.py build --set rust.debug=true opt-dist && PGO_HOST=x86_64-pc-windows-msvc ./build/x86_64-pc-windows-msvc/stage1-tools-bin/opt-dist windows-ci -- python x.py dist bootstrap --include-default-paths
664665
DIST_REQUIRE_ALL_TOOLS: 1

src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ extern crate test;
6262
/// FIXME(madsmtm): This is loaded from the sysroot that was built with the other `rustc` crates
6363
/// above, instead of via Cargo as you'd normally do. This is currently needed for LTO due to
6464
/// https://github.com/rust-lang/cc-rs/issues/1613.
65-
#[cfg(feature = "override_allocator")]
65+
#[cfg(all(feature = "override_allocator", not(target_os = "windows")))]
6666
extern crate tikv_jemalloc_sys as _;
6767

6868
use std::env::{self, VarError};

src/tools/clippy/src/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern crate rustc_span;
1717
/// FIXME(madsmtm): This is loaded from the sysroot that was built with the other `rustc` crates
1818
/// above, instead of via Cargo as you'd normally do. This is currently needed for LTO due to
1919
/// <https://github.com/rust-lang/cc-rs/issues/1613>.
20-
#[cfg(feature = "override_allocator")]
20+
#[cfg(all(feature = "override_allocator", not(target_os = "windows")))]
2121
extern crate tikv_jemalloc_sys as _;
2222

2323
use clippy_utils::sym;

src/tools/miri/src/bin/miri.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern crate rustc_span;
2424
/// FIXME(madsmtm): This is loaded from the sysroot that was built with the other `rustc` crates
2525
/// above, instead of via Cargo as you'd normally do. This is currently needed for LTO due to
2626
/// https://github.com/rust-lang/cc-rs/issues/1613.
27-
#[cfg(feature = "override_allocator")]
27+
#[cfg(all(feature = "override_allocator", not(target_os = "windows")))]
2828
// Make sure `--all-features` works: only Linux and macOS actually use jemalloc, and not on arm32.
2929
#[cfg(all(
3030
any(target_os = "linux", target_os = "macos"),

src/tools/tidy/src/deps.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
356356
"leb128",
357357
"libc",
358358
"libloading",
359+
"libmimalloc-sys",
359360
"linux-raw-sys",
360361
"litemap",
361362
"lock_api",
@@ -365,6 +366,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
365366
"measureme",
366367
"memchr",
367368
"memmap2",
369+
"mimalloc",
368370
"miniz_oxide",
369371
"nix",
370372
"nu-ansi-term",

0 commit comments

Comments
 (0)