From b7453a25d7fda0921b91e476086ae7773cc6e09d Mon Sep 17 00:00:00 2001 From: Yujong Lee Date: Thu, 3 Sep 2026 10:15:03 -0700 Subject: [PATCH] perf(rust): make mimalloc opt-in behind a cargo feature pydantic-core shipped mimalloc from Jun 2022 to Aug 2023 and removed it (pydantic-core#900) after: a TLS-linkage fix (pydantic-core#363), manylinux cross-compile breakage (pydantic-core#893), 1GiB of reserved virtual memory at import breaking RLIMIT_AS-limited processes (pydantic#7167), and container memory-footprint complaints (pydantic#6620). litellm wheels land in exactly those memory-limited container deployments, so the allocator override must be an explicit build-time choice, not a default imposed on every wheel. The feature stays available for self-built deployments that want it; wheels build without it. --- litellm-rust/crates/python-bridge/Cargo.toml | 3 ++- litellm-rust/crates/python-bridge/src/lib.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/litellm-rust/crates/python-bridge/Cargo.toml b/litellm-rust/crates/python-bridge/Cargo.toml index c4be72ab8f5..ccefd910396 100644 --- a/litellm-rust/crates/python-bridge/Cargo.toml +++ b/litellm-rust/crates/python-bridge/Cargo.toml @@ -13,11 +13,12 @@ crate-type = ["cdylib"] default = ["abi3"] abi3 = ["pyo3/abi3-py310"] extension-module = ["pyo3/extension-module"] +mimalloc = ["dep:mimalloc"] panic-test = [] [dependencies] futures-util.workspace = true -mimalloc.workspace = true +mimalloc = { workspace = true, optional = true } tracing.workspace = true tracing-subscriber.workspace = true litellm-core = { workspace = true, features = ["bedrock-auth"] } diff --git a/litellm-rust/crates/python-bridge/src/lib.rs b/litellm-rust/crates/python-bridge/src/lib.rs index 7e160a4c7bf..cab860a91d1 100644 --- a/litellm-rust/crates/python-bridge/src/lib.rs +++ b/litellm-rust/crates/python-bridge/src/lib.rs @@ -11,6 +11,7 @@ use pyo3::prelude::*; use pyo3::types::PyAny; use serde_json::Value; +#[cfg(feature = "mimalloc")] #[global_allocator] static ALLOCATOR: mimalloc::MiMalloc = mimalloc::MiMalloc;