TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #25166 10
Built a dpdk-inspired lock-free queue and found some surprising perf behavior

Built a lock-free ring queue in C++ inspired by DPDK `rte_ring`.

Expected to spend most of the time investigating cache coherency and inter-core synchronization.

Didn’t expect compiler codegen and tiny abstractions to matter this much.

Some interesting findings:

* avoiding grouped producer/consumer structs reduced \~300k instructions, \~200k branches and \~100k cache misses
* adding a single variable(for batching) and using template abstraction measurably changed generated assembly
* two specialized classes generated better code than one generic template-heavy abstraction
* GCC was much more sensitive to benchmark-harness overhead while Clang optimized through it better (32-byte payload throughput: \~8M ops/sec vs \~52M ops/sec before fixing the harness)

Benchmarked against:

* Rigtorp
* Drogalis
* Boost SPSC
* MoodyCamel

Current focus:

* SPSC latency
* batching/publication tuning
* cache coherency behavior

Note: Have not much explored the mpmc yet neither exposed its benchmarking strategy.
I felt like although my code was relatively easier to comprehend, although my throughput is better than them, my latency is to be improved currently 10-20 more cycles than rigtorp and drogalis.

Would appreciate feedback from people experienced with low-latency systems / lock-free structures.

[https://github.com/shuraih775/lfqueue](https://github.com/shuraih775/lfqueue)

https://redd.it/1t96fqb
@r_cpp
GitHub GitHub - shuraih775/LFQueue: A lock free ring buffer inspired by rte_ring. A lock free ring buffer inspired by rte_ring. Contribute to shuraih775/LFQueue development by creating an account on GitHub.
More from @r_cpp
  1. Oct 3, 2026C++ Show and Tell - October 2026 Use this thread to share anything you've written in C++.…
  2. Oct 3, 2026C++ future at Adobe So if anyone was still curious what happened to Hylo, or where Adobe s…
  3. Oct 3, 2026C++ Jobs - Q4 2026 Rules For Individuals --------------------- * **Don't** create top-leve…
  4. Sep 29, 2026Boost.Graph 1.95 will be C++17 Dear Boost.Graph community, In two release cycles (Boost re…
  5. Sep 26, 2026Token Sequence Injection & Modern Macros: The Most Game-Changing Compile-Time Feature in C…
  6. Sep 25, 2026myStringStream.str("") Considered Harmful Under C++20 I was recently looking at some (rath…
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 →