perf(ppvm-python-native): use mimalloc as the global allocator#129
perf(ppvm-python-native): use mimalloc as the global allocator#129AlexSchuckert wants to merge 1 commit into
Conversation
mimalloc returns freed pages to the OS more aggressively than the default system allocator, materially reducing peak RSS on the allocation-heavy Pauli-propagation paths (each gate / truncation step churns large transient Vec / HashMap buffers). Set as the `#[global_allocator]` for the Python extension module. Split out of #98 per review feedback so the allocator change can be reviewed and benchmarked on its own rather than bundled into a feature PR. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR configures the ppvm-python-native (PyO3) extension module to use mimalloc as the Rust global allocator to reduce peak RSS on allocation-heavy Pauli-propagation workloads.
Changes:
- Add
mimallocas a dependency ofcrates/ppvm-python-native. - Declare
mimalloc::MiMallocas the#[global_allocator]in the extension crate. - Update
Cargo.lockto includemimalloc/libmimalloc-sys.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/ppvm-python-native/src/lib.rs | Sets mimalloc as the global allocator for the extension module. |
| crates/ppvm-python-native/Cargo.toml | Adds the mimalloc dependency needed by the allocator change. |
| Cargo.lock | Locks mimalloc and its transitive libmimalloc-sys dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| [dependencies] | ||
| bnum = "0.13.0" | ||
| mimalloc = { version = "0.1", default-features = false } | ||
| num = "0.4.3" |
| // 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; |
|
|
Ran an allocator A/B for this PR locally on Linux x86_64. Setup:
Results:
Conclusion: these Linux results do not support the stated RSS/memory-throughput rationale. Throughput is neutral on the small Trotter workload, and the memory-stress workload retains substantially more resident memory with mimalloc. Closing this PR rather than taking the allocator change as-is. |
What
Sets
mimallocas the#[global_allocator]for theppvm_python_nativeextension module.Why
mimalloc returns freed pages to the OS more aggressively than the default system allocator. This materially reduces peak RSS on the allocation-heavy Pauli-propagation paths, where each gate / truncation step churns large transient
Vec/HashMapbuffers that the system allocator tends to retain.Split out of #98 per review feedback (@Roger-luo): the allocator is an independent optimization and shouldn't be bundled into a feature PR — this lets it be reviewed and benchmarked on its own.
Changes
crates/ppvm-python-native/Cargo.toml: addmimalloc = { version = "0.1", default-features = false }.crates/ppvm-python-native/src/lib.rs: declare the global allocator (with a justifying comment).Validation
maturin develop --releasebuilds and links cleanly.pytest ppvm-python/test/test_basics.pygreen (smoke).No API or behavior change — allocator only.
🤖 Generated with Claude Code