From 773b78f4ae321b510ee8d0ae7dc42a9dc92d5fd0 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 29 Jan 2026 13:03:25 +0000 Subject: [PATCH] Use jemalloc for Rust --- Cargo.lock | 21 +++++++++++++++++++++ rust/Cargo.toml | 4 ++++ rust/src/lib.rs | 3 +++ 3 files changed, 28 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 0edfef6869..b259bc6b0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1339,6 +1339,7 @@ dependencies = [ "serde", "serde_json", "sha2", + "tikv-jemallocator", "tokio", "ulid", ] @@ -1389,6 +1390,26 @@ dependencies = [ "syn", ] +[[package]] +name = "tikv-jemalloc-sys" +version = "0.6.1+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd8aa5b2ab86a2cefa406d889139c162cbb230092f7d1d7cbc1716405d852a3b" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0359b4327f954e0567e69fb191cf1436617748813819c94b8cd4a431422d053a" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "tinystr" version = "0.8.1" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 350701d327..ef20df045d 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -53,6 +53,10 @@ http-body-util = "0.1.3" futures = "0.3.31" tokio = { version = "1.44.2", features = ["rt", "rt-multi-thread"] } once_cell = "1.18.0" +tikv-jemallocator = { version = "0.6", features = [ + "unprefixed_malloc_on_supported_platforms", + "disable_initial_exec_tls", +] } [features] extension-module = ["pyo3/extension-module"] diff --git a/rust/src/lib.rs b/rust/src/lib.rs index fe880af2ea..5f937bd835 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -16,6 +16,9 @@ pub mod push; pub mod rendezvous; pub mod segmenter; +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + lazy_static! { static ref LOGGING_HANDLE: ResetHandle = pyo3_log::init(); }