diff --git a/Cargo.lock b/Cargo.lock index 99834ef11..adaf79446 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -644,6 +644,15 @@ version = "0.2.176" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174" +[[package]] +name = "libmimalloc-sys" +version = "0.1.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9" +dependencies = [ + "cc", +] + [[package]] name = "linux-raw-sys" version = "0.11.0" @@ -672,6 +681,15 @@ version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +[[package]] +name = "mimalloc" +version = "0.1.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "num" version = "0.4.3" @@ -844,6 +862,7 @@ name = "ppvm-python-native" version = "0.1.0" dependencies = [ "bnum", + "mimalloc", "num", "paste", "ppvm-runtime", diff --git a/crates/ppvm-python-native/Cargo.toml b/crates/ppvm-python-native/Cargo.toml index 6b6e59242..e4f34cf64 100644 --- a/crates/ppvm-python-native/Cargo.toml +++ b/crates/ppvm-python-native/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["cdylib"] [dependencies] bnum = "0.13.0" +mimalloc = { version = "0.1", default-features = false } num = "0.4.3" paste = "1.0.15" ppvm-runtime = { version = "0.1.0", path = "../ppvm-runtime" } diff --git a/crates/ppvm-python-native/src/lib.rs b/crates/ppvm-python-native/src/lib.rs index 8924db9dc..9aefad2e9 100644 --- a/crates/ppvm-python-native/src/lib.rs +++ b/crates/ppvm-python-native/src/lib.rs @@ -1,6 +1,13 @@ // SPDX-FileCopyrightText: 2026 The PPVM Authors // SPDX-License-Identifier: Apache-2.0 +// Use mimalloc as the global allocator. It returns freed pages to the OS +// more aggressively than the default system allocator, which materially +// reduces peak RSS on the allocation-heavy Pauli-propagation paths — each +// gate / truncation step churns large transient `Vec` / `HashMap` buffers. +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + use pyo3::prelude::*; pub mod interface;