From adab7124ea78c9ead4264862db6deea1d0bfd447 Mon Sep 17 00:00:00 2001 From: x-hgg-x <39058530+x-hgg-x@users.noreply.github.com> Date: Tue, 15 Oct 2024 08:58:11 +0200 Subject: [PATCH] fix(perf): switch global allocator to jemalloc --- Cargo.lock | 21 +++++++++++++++++++++ Cargo.toml | 4 ++++ src/bin/cargo/main.rs | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index a943b8b8c40a..b6c181b14105 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -358,6 +358,7 @@ dependencies = [ "tar", "tempfile", "thiserror", + "tikv-jemallocator", "time", "toml", "toml_edit", @@ -3472,6 +3473,26 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tikv-jemalloc-sys" +version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd3c60906412afa9c2b5b5a48ca6a5abe5736aec9eb48ad05037a677e52e4e2d" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cec5ff18518d81584f477e9bfdf957f5bb0979b0bac3af4ca30b5b3ae2d2865" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "time" version = "0.3.36" diff --git a/Cargo.toml b/Cargo.toml index 18b5015a0e6d..ea7d6f61c943 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,6 +99,7 @@ snapbox = { version = "0.6.18", features = ["diff", "dir", "term-svg", "regex", tar = { version = "0.4.42", default-features = false } tempfile = "3.10.1" thiserror = "1.0.63" +tikv-jemallocator = "0.6" time = { version = "0.3.36", features = ["parsing", "formatting", "serde"] } toml = "0.8.19" toml_edit = { version = "0.22.20", features = ["serde"] } @@ -243,6 +244,9 @@ features = [ "Win32_System_Threading", ] +[target.'cfg(not(target_env = "msvc"))'.dependencies] +tikv-jemallocator.workspace = true + [dev-dependencies] annotate-snippets = { workspace = true, features = ["testing-colors"] } cargo-test-support.workspace = true diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index fa41e9c3ff47..a004ddce106b 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(not(target_env = "msvc"))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + use cargo::core::features; use cargo::core::shell::Shell; use cargo::util::network::http::http_handle;