TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #24902 20
Iteratively optimizing an SPSC queue

I recently documented walking through the iterative process of optimizing a SPSC queue.

* Starting from `atomic<int64_t> size` which has the `lock` instruction bottleneck.
* Refactoring to separate atomic push, popInd. Fixing false sharing, 3 cacheline and 2 cacheline approach.
* Implementing index caching to minimize cross-core traffic and the impact of mm_pause

Link: https://blog.c21-mac.com/posts/spsc/

For reasons I don't understand the 3 cacheline performs considerably worse than 2 cacheline, I initially assumed it due to 128-byte-rule, but that doesn't explain L1d-cache misses being relatively higher in 3 cacheline vs 2 cacheline implementation. If anyone has any insights on what might be causing this or any feedback on the post, I would love to hear.


https://redd.it/1s80568
@r_cpp
C21 Blog Optimizing a Lock-Free SPSC Queue Yet another SPSC blog! The goal isn’t just to explain a final solution, such as the lock-free, index-cached implementation some of you might already know. Instead, I want to walk through the iterative process: testing different approaches, analyzing the results…
More from @r_cpp
  1. Oct 7, 2026Episode 411 : CppCast - Kevin Carpenter - Volunteering (and speaking) at C++ conference, a…
  2. Oct 7, 2026Bugbusters #1 | C++ in 2026: worth it? | Nathan Baggs https://youtube.com/watch?v=kd-5hJHv…
  3. Oct 6, 2026Implementation of GCC's Nested Functions (vs. C++ Lambdas) https://uecker.codeberg.page/20…
  4. Oct 6, 2026C++26: Module improvements https://www.sandordargo.com/blog/2026/09/09/cpp26-modules https…
  5. Oct 6, 2026Tuning a Server for Benchmarking https://david.alvarezrosa.com/posts/tuning-a-server-for-b…
  6. Oct 6, 2026boost.org has been rebuilt: new profiles, badges, search, and library filtering The Boost…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →