C++23 for Low-Latency Trading
From what is a class to cache-line padding, branchless decoding and a wait-free order book. Every chapter earns its place on a hot path: if it does not show up in a tick-to-trade profile, it is not here.
How to use this series
- Read a lesson, then compile its snippets. Nothing here is theoretical.
- Paste the hot ones into a disassembler and read the output. The assembly is the ground truth.
- Measure before you believe. Part IV teaches you how to measure without lying to yourself.
Compiles with GCC 14+ or Clang 18+ using -std=c++23 -O2.
Linux-specific material is flagged where it appears.
Where to start
- New to C++. Lessons 01 to 18 in order. Do not skip ahead to Part III: the optimisation material assumes you can read the code it optimises. Set up the interactive session from lesson 01a early; it makes every later lesson faster to explore.
- Fluent in C++, new to latency. Skim Part II for the C++23 additions, then start at lesson 19. Part III is the core of the series.
- Already writing hot paths. Lessons 24, 26, 32, 33 and 39 are the ones that change how a system is built. Lesson 43 is a review checklist you can use tomorrow.
- Chasing a tail you cannot explain. Lesson 28a for tracing, since a sampling profiler structurally cannot see a one-in-a-million event, then lesson 29a for the build-level wins that cost an afternoon and no design change.
Curriculum
Part I - Foundations
The language from zero: translation units, classes, enums, pointers, value categories, ownership.
Part II - Modern C++23
Compile-time computation, concepts, views and vocabulary types that cost nothing at run time.
Part III - The Machine
Caches, alignment, branch prediction, inlining, allocation-free data structures.
Part IV - Latency Engineering
Measuring nanoseconds honestly, then removing them: layout, prefetch, SIMD, PGO.
Part V - Concurrency
Atomics, memory ordering, wait-free queues, core pinning, seqlocks for market data.
Part VI - Trading Systems
Feed handlers, order books, tick-to-trade paths and a capstone you can compile.
Appendix
Reference cards, compiler flags, further reading.