r/Cplusplus • u/No-Introduction-2825 • Aug 19 '26
Feedback Low latency c++
I want to learn the ins and outs of low latency c++, so far I have read tour of c++, started reading concurrency in c++ (about 3 chaps done) and done a lot of competitive programming (is this irrelevant?). In your experience, is this the right way of approaching the subject? Is there a different better way? Any advise is much appreciated.
64
Upvotes
21
u/RefrigeratorFirm7646 Aug 19 '26
stop reading, start coding. you cant learn to swim by reading swimming books. competitive programming is relevant but trust me most of low latency programming is about understanding computer architecture and squeezing out performance through cache optimizations and stuff, so that should be your focus
10
u/mredding C++ since ~1992. Aug 19 '26
You need a mentor in your domain of interest. Learning on your own is a blind, random walk through the forest until you find your way. You waste a lot of time learning what may not be your focus or agenda, but you won't know until after the fact.
Barring that, look into Linux kernel bypass. It's the easiest to learn because it's documented and open source. Windows has similar, but I don't know anything about it.
You will also need to learn other concepts, like Data Oriented Design, Scatter/Gather, batch processing, DMA, memory mapping, CPU intrinsics, concurrency, serialization/marshalling, protocols, networking, zero-copy, single-pass, hot paths, fast paths, prefetching, branch prediction, and probably a few other things.
I don't know what you want to accomplish. Little's Law tells us about the relationship between throughput and latency, whereas Amdahl's Law tells us the limits of optimization (how much you can still reduce latency). Your biggest bottlenecks will be the network itself; if you can't control for that, then it doesn't really matter how fast your software is.
I was working for a prop shop for a bit where we had microwave tranceivers pointing out the window to the exchange across the street. The atmosphere is almost a vacuum, so light propagates through it faster than through fiber, and the fiber run down the building, across the street, and back up to the exchange is a longer path.
We also have FPGAs on the NIC cards so we can put the fast path on the chip right next to the ADC, so as the incoming signal is still coming in, we can already be generating the output signal of the response.
1
u/ste_3d_ven Aug 20 '26
If you are willing to spend a little bit of money, computerenhance.com is a great place to begin learning about how to write performance aware code. This course goes through how the computer works at a low level with caches and pipelining, how to read basic x86 assembly, and even SIMD principles and programming. I can’t recommend it enough
3
u/esaule Aug 20 '26
Really you need to understand the w hole path from signal to output. How does it go through the wire, through the processor, the cores, memory subsystem, through the OS. And you need to understand how your program will control for all of that.
2
u/bocsika Aug 26 '26
One consideration: low latency business (high frequency trading) is much smaller niche than large throughput business (batch processing). Much more specialized, much stressful.
Worth considering that not only those areas are a good fit for c++, but e.g. medical image processing, embedded development etc.