Skip to content

feat! Mimalloc as the default allocator #434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anakrish
Copy link
Collaborator

@anakrish anakrish commented Jul 11, 2025

Using a custom allocator like Mimalloc brings upto 30% speed improvements
for many workloads.

The code and approach (vendored) for using mimalloc is borrowed from
QSharp (https://github.com/microsoft/qsharp/tree/main/source/allocator).

Also added ACI benchmark to measure evaluation times.

@anakrish anakrish force-pushed the mimalloc branch 2 times, most recently from 689449a to 1796833 Compare July 11, 2025 16:19
Using a custom allocator like Mimalloc brings upto 30% speed improvements
for many workloads.

The code and approach (vendored) for using mimalloc is borrowed from
QSharp (https://github.com/microsoft/qsharp/tree/main/source/allocator).

Also added ACI benchmark to measure evaluation times.

Signed-off-by: Anand Krishnamoorthi <[email protected]>
@anakrish anakrish marked this pull request as ready for review July 11, 2025 16:43
@anakrish anakrish requested a review from Copilot July 11, 2025 16:43
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!() to src/lib.rs under the mimalloc feature
  • Introduce new mimalloc crate implementing GlobalAlloc with tests for alloc and alloc_zeroed
  • Define and expose the assign_global macro and FFI bindings in mimalloc-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 realloc method 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 mimalloc module duplicates the crate name, which may be confusing; consider renaming the module to something more descriptive like allocator or global.
pub mod mimalloc;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant