feat! Mimalloc as the default allocator#434
Merged
Merged
Conversation
1796833 to
2d21208
Compare
There was a problem hiding this comment.
Pull Request Overview
Enable the use of Mimalloc as the global allocator under a cargo feature and bundle the Mimalloc C library via a Rust FFI layer.
- Add
mimalloc::assign_global!()tosrc/lib.rsunder themimallocfeature - Introduce new
mimalloccrate implementingGlobalAllocwith tests forallocandalloc_zeroed - Define and expose the
assign_globalmacro and FFI bindings inmimalloc-sys
Reviewed Changes
Copilot reviewed 49 out of 56 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/lib.rs | Call mimalloc::assign_global!() when feature = "mimalloc" |
| mimalloc/src/mimalloc.rs | Implement GlobalAlloc in Mimalloc and add basic allocation tests |
| mimalloc/src/lib.rs | Export assign_global macro |
| mimalloc/mimalloc-sys/src/lib.rs | Declare extern C bindings for allocation functions |
Comments suppressed due to low confidence (2)
mimalloc/src/mimalloc.rs:30
- Consider adding a test for the
reallocmethod to verify that data is correctly preserved and the pointer is properly reallocated.
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
mimalloc/src/lib.rs:5
- [nitpick] The
mimallocmodule duplicates the crate name, which may be confusing; consider renaming the module to something more descriptive likeallocatororglobal.
pub mod mimalloc;
2d1c979 to
b00bf49
Compare
This change integrates mimalloc as the default memory allocator for Regorus, delivering significant performance improvements across all evaluation modes and language bindings. Technical Implementation: - Build mimalloc in vendored mode from C sources (following QSharp approach) - Implement GlobalAlloc trait for seamless Rust integration - Add optional 'mimalloc' feature flag for conditional compilation - Add comprehensive ACI benchmarks to measure evaluation performance Performance Impact: Rust Engine Evaluation: - Single-threaded: ~29% improvement (423 vs 328 Kelem/s) - Multi-threaded: Better scaling with reduced thread contention - Fresh engines: ~24% improvement (56 vs 45 Kelem/s) Rust Compiled Policy Evaluation: - Single-threaded: ~41% improvement (426 vs 303 Kelem/s) - Multi-threaded: Improved allocation efficiency under contention - Fresh compilation: ~26% improvement (53 vs 42 Kelem/s) C# FFI Bindings: - Engine evaluation: ~27% improvement (279 vs 219 Kelem/s) - Compiled policies: ~29% improvement (273 vs 211 Kelem/s) - Better threading characteristics through improved underlying allocation Key Benefits: - Reduced allocation-related contention in multi-threaded scenarios - More consistent performance across different thread counts - Improved memory allocation efficiency for both native Rust and FFI workloads - Better scaling characteristics for production deployments The mimalloc integration provides substantial performance gains while maintaining full compatibility with existing code through feature flags. Reference: QSharp allocator implementation (https://github.com/microsoft/qsharp/tree/main/source/allocator) Fixes microsoft#297 Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change integrates mimalloc as the default memory allocator for Regorus,
delivering significant performance improvements across all evaluation modes
and language bindings.
Technical Implementation:
Performance Impact:
Rust Engine Evaluation:
Rust Compiled Policy Evaluation:
C# FFI Bindings:
Key Benefits:
The mimalloc integration provides substantial performance gains while
maintaining full compatibility with existing code through feature flags.
Reference: QSharp allocator implementation
(https://github.com/microsoft/qsharp/tree/main/source/allocator)
Fixes #297