← Projects

hpalloc

An allocator for research and experimentation in settings where allocation latency matters more than fragmentation. It is built in three layers:

  • Arena. An mmap-backed pool that hands out 4 KB page-aligned chunks in order, with no deallocation.
  • Fixed-size block allocator. Splits pages into fixed-size blocks and manages them with a pointer free list. Allocation and deallocation take constant time.
  • Size-class allocator. One block allocator per size class (32, 64, 128, and 256 bytes). Requests are rounded up to the nearest class.

Benchmark (block size 64, 10,000,000 allocations, Ryzen 5 3550H, Fedora 42)

AllocatorTotal timeAvg latencyP99 latencyRSS
hpalloc~980 ms~98 ns51 ns~160 MB
malloc~1,840 ms~184 ns~2,970 ns~941 MB

Bar charts comparing hpalloc and malloc on average latency, p99 latency and resident memory

The same benchmark as the table, averaged over five runs. The biggest difference is in tail latency and memory, not the average.

It is not meant for general use: there is no bounds checking and no thread safety, and freeing a block with the wrong size class is undefined behavior.