Top 3 Custom Allocators Surpassing malloc for Speed
For specific high-performance, large data workloads, custom memory allocators often outperform the default `malloc`. `jemalloc`, `tcmalloc` (Google), and `mimalloc` (Microsoft) are leading alternatives. `mimalloc` often shows lower P99 latency for small, frequent allocations, while `tcmalloc` and `jemalloc` remain competitive for very large allocations and often reduce memory fragmentation and consumption compared to `glibc malloc`. `jemalloc` provides extensive tuning options, `tcmalloc` excels in multi-threaded throughput via per-thread caches, and `mimalloc` focuses on compact, fast, and low-fragmentation designs.
The top 3
- mimalloc: Microsoft's Low-Latency Champion: Microsoft Research's mimalloc (pronounced "me-malloc") often outperforms other leading allocators like jemalloc and tcmalloc, particularly in benchmarks involving object migration between threads, achieving more than 2.5x speedup in some server workloads. Its design emphasizes low-latency allocation and deallocation through per-thread heaps and innovative free list sharding to minimize contention and improve cache locality.
- TCMalloc: Google's Thread-Caching Speed Demon: Google's TCMalloc (Thread-Caching Malloc) significantly accelerates memory operations, achieving approximately 50 nanoseconds for a malloc/free pair for small objects, compared to roughly 300 nanoseconds for glibc's ptmalloc2. It minimizes lock contention in multi-threaded programs by using thread-local caches for small objects, making most allocations and deallocations lock-free and highly scalable.
- jemalloc: FreeBSD's High-Concurrency Powerhouse: Originally developed for FreeBSD, jemalloc is known for its excellent multi-threading performance and low fragmentation, being the default allocator for Firefox, Redis, and many other high-performance applications, often outperforming `malloc` and `tcmalloc` in specific high-concurrency workloads.
Sources
Open the full topic