r/cpp • u/david-alvarez-rosa • Mar 24 '26
Optimizing a Lock-Free Ring Buffer
https://david.alvarezrosa.com/posts/optimizing-a-lock-free-ring-buffer/
105
Upvotes
r/cpp • u/david-alvarez-rosa • Mar 24 '26
View all comments
2
u/A8XL Mar 31 '26
Nice article! I have implemented a user-friendly Lock-Free Ring Buffer that incorporates all these optimizations:
https://github.com/joz-k/LockFreeSpscQueue
I have also included a built-in performance benchmark against
moodycamel::ReaderWriterQueue.The techniques in your article are powerful, but they are not sufficient to outperform more complex solutions in a synthetic benchmarks like this one using a simple single item push/pop API:
https://max0x7ba.github.io/atomic_queue/html/benchmarks.html
See my performance analysis. My
LockFreeSpscQueueis significantly faster for a larger batch transfers only. However, it is highly scalable.