Benchmark Report: Analyzing the Time-Space Trade-off in Memory Allocators (hakozuna vs tcmalloc)
Source: Dev.to
Benchmark Overview
A custom memory allocator, hz3 (referred to as hakozuna), was evaluated against two industry‑standard allocators:
- tcmalloc (Google)
- mimalloc (Microsoft)
The focus was on the trade‑off between execution speed and memory footprint (RSS).
Test Environment
- CPU: AMD Ryzen 9 9950X
- Runs per test: 5 (median values reported)
Results
1. Espresso (Real‑world simulation)
| Allocator | Time | RSS | Notes |
|---|---|---|---|
| tcmalloc | 2.43 s | 9.7 MB | Fastest, but highest memory usage |
| mimalloc | 2.45 s | 4.0 MB | Balanced |
| hakozuna | 2.75 s | 2.6 MB | Slowest (+13 %), but lowest memory |
2. Alloc‑test (Synthetic)
| Allocator | Time | RSS | Notes |
|---|---|---|---|
| tcmalloc | 1.99 s | 18.2 MB | |
| mimalloc | 2.00 s | 22.0 MB | |
| hakozuna | 2.51 s | 14.5 MB | Smallest footprint |
Analysis
The Cost of Speed
- tcmalloc achieved the fastest execution times in both benchmarks.
- It consumed significantly more memory (≈ 3.7× higher RSS in the Espresso test: 9.7 MB vs 2.6 MB).
- The allocator aggressively caches freed memory in thread‑local storage, minimizing locking and CPU overhead at the expense of a larger memory footprint.
The Cost of Frugality
- hakozuna consistently recorded the lowest RSS.
- This is due to an aggressive purging strategy that returns unused pages to the OS and a compact metadata design.
- The reduced memory usage comes with a modest increase in execution time.
Choosing the Right Allocator
- Latency‑sensitive applications with ample RAM: tcmalloc or mimalloc remain superior choices.
- Memory‑constrained environments (e.g., high‑density microservices, embedded systems): hakozuna offers a viable alternative by markedly lowering memory consumption, accepting a slight CPU penalty.
Conclusion
The benchmark underscores that “performance” is not a single metric. It is always a balance between time (execution speed) and space (memory usage). Selecting an allocator should be guided by the specific priorities of the target workload.