PSA: You can easily swap Rust’s allocator for better concurrency—here’s a crate that automates it

52 points Working-Comfort-2514 47 comments

Hey everyone,

Just wanted to share a crate I’ve been working on: auto-allocator.

Why does this matter?
The default system allocator (like glibc malloc) can become a performance bottleneck under high concurrency due to global locking. Modern allocators such as mimalloc or jemalloc use thread-local caches and optimized strategies to improve throughput and reduce fragmentation.

Instead of manually configuring allocators with #[cfg] and platform checks, auto-allocator automatically picks the recommended allocator for your target platform:

  • Linux/macOS/Windows: mimalloc
  • Android: scudo
  • iOS: system allocator
  • WASM: default allocator for compatibility
  • Embedded/no_std: embedded-alloc

Usage:

[dependencies]
auto-allocator = "*"

---

use auto_allocator; //  Done! Memory allocation is now optimized

fn main() {
    let info = auto_allocator::get_allocator_info();
    println!(
        "Using allocator: {:?}, reason: {}",
        info.allocator_type, info.reason
    );

    // your code here
}

If you’re curious about the performance impact, there are some references:

I’d be happy to hear any feedback or ideas. Thanks!

✅ GitHub: https://github.com/YeautyYE/auto-allocator