diff --git a/Cargo.lock b/Cargo.lock index a943b8b8c40a..7d07078784ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -334,6 +334,7 @@ dependencies = [ "libc", "libgit2-sys", "memchr", + "mimalloc", "opener", "openssl", "os_info", @@ -2245,6 +2246,16 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libmimalloc-sys" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23aa6811d3bd4deb8a84dde645f943476d13b248d818edcf8ce0b2f37f036b44" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "libnghttp2-sys" version = "0.1.10+1.61.0" @@ -2362,6 +2373,15 @@ dependencies = [ "libc", ] +[[package]] +name = "mimalloc" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68914350ae34959d83f732418d51e2427a794055d0b9529f48259ac07af65633" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "minimal-lexical" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 18b5015a0e6d..8867169215b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,6 +66,7 @@ libc = "0.2.155" libgit2-sys = "0.17.0" libloading = "0.8.5" memchr = "2.7.4" +mimalloc = "0.1.43" miow = "0.6.0" opener = "0.7.1" openssl = "=0.10.57" # See rust-lang/cargo#13546 and openssl/openssl#23376 for pinning @@ -181,6 +182,7 @@ jobserver.workspace = true lazycell.workspace = true libgit2-sys.workspace = true memchr.workspace = true +mimalloc = { workspace = true, optional = true } opener.workspace = true os_info.workspace = true pasetors.workspace = true @@ -260,6 +262,8 @@ test = false doc = false [features] +default = ["mimalloc"] +mimalloc = ["dep:mimalloc"] vendored-openssl = ["openssl/vendored"] vendored-libgit2 = ["libgit2-sys/vendored"] # This is primarily used by rust-lang/rust distributing cargo the executable. diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index fa41e9c3ff47..a0b736bd9361 100644 --- a/src/bin/cargo/main.rs +++ b/src/bin/cargo/main.rs @@ -1,5 +1,9 @@ #![allow(clippy::self_named_module_files)] // false positive in `commands/build.rs` +#[cfg(feature = "mimalloc")] +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + use cargo::core::features; use cargo::core::shell::Shell; use cargo::util::network::http::http_handle;