Latency: A Practical Guide in C++
A chapter-based guide to latency engineering in C++23, one pattern per chapter, measured on a parcel sortation line.
What this guide is
A chapter-based, hands-on path through latency engineering in C++23. Every chapter measures one pattern against the same running example: a parcel sortation line moving a parcel through checkweigh, dimension, scan, label, and sort. The metric that matters is scan-to-divert, the time from sensing a parcel to acting on it, because the belt never waits for a slow consumer. Three chapters add a Rust lane side by side in the tabbed code component, where ownership and the type system change what a technique has to prove. One chapter runs in a throwaway virtual machine; the rest run unprivileged, on the host, as they are.
Measuring Latency
Establish the running example and the harness, then learn to read a latency distribution and set a budget before touching any code.
Eliminating Work
The cheapest latency fix is work you never do: precompute, lay out memory for the access pattern, and stop paying for copies.
Concurrency and Synchronization
Hand off work between threads without a lock, and split it across cores correctly.
Scaling and the Host
Scale a single box with caching and shard-per-core partitioning, move the slow parts off the hot path, then see what the host itself costs you and when it's worth taming. The pattern catalog closes out the part and the main guide, before the appendices reach past a single box.
Appendices
Material that reaches past the single-box spine of the main guide. The first appendix measures how a latency-sensitive handoff behaves when it has to cross from one virtual machine to another on the same host, where shared memory, a socket, and a shared filesystem sit on very different rungs of the same ladder.