When Nanoseconds Matter: Ultrafast Trading Systems in C++
Talkat CppCon 2024 · on Thursday, 2024-09-19· at 10:30· Adams A, 6700 North Gaylord Rockies Boulevard·
summary
Claims are concrete: an order book with ~1000 levels per side is fastest as a contiguous array reversed so top‑of‑book updates avoid vector shifts, linear search beats binary on hot short ranges and branchless lower_bound raises IPC from ~1.4 to ~1.6. Tools are real: perf, hardware counters, clang x‑ray, AMD Z4 Zen4 microbenchmarks, Solarflare/onload and efvi/DPDK for networking. Numbers that surprise: kernel UDP ≈3 μs vs ≈700 ns layer‑2 UDP, 73‑byte messages for queue tests. Built pieces: a simple 150‑line shared‑memory bounded queue with reservation trick (reserve 100 KB) that reduces atomic contention and measures well.
AI-written summary · about
chapters (37)
- 0:00Ultrafast trading systems intro
- 1:16Roman Empire lessons on planning
- 4:50Market making as losers game
- 7:57Software still matters in low latency
- 10:45Order book fundamentals and data structures
- 15:39Order book with std::map limitations
- 17:23Latency distribution of data structures
- 20:11Avoid node-based containers
- 21:57Replace std::map with std::vector
- 25:50Understand domain for half-solved problems
- 26:55Leverage problem-specific properties
- 27:16Profiling with perf and Top-Down Analysis
- 30:07Branch mispredictions in binary search
- 31:51Branchless binary search optimizations
- 33:37Simplicity as ultimate optimization
- 35:44Mechanical sympathy with hardware
- 36:47Instruction cache and inlining trade-offs
- 39:16Lambda optimizations pitfalls
- 40:19Networking and concurrency in low latency
- 41:23Bypass kernel for ultra-low latency
- 42:25Networking APIs performance comparison
- 43:07Mindful use of system components
- 44:29Shared memory fundamentals
- 45:56Bounded concurrent queues design
- 49:11Right concurrency tool choice
- 51:21Fast concurrent queue with atomics
- 53:06Data races and atomic operations
- 54:35Concurrent queue benchmarks
- 56:01Atomic counter batching optimization
- 1:01:16Intrusive profiling for bottlenecks
- 1:04:43Clang X-Ray for production profiling
- 1:06:29Stay fast with constant vigilance
- 1:07:56System-wide performance awareness
- 1:09:20Cache hierarchy impact on workers
- 1:13:13No silver bullets in low latency
- 1:14:39References and further learning
- 1:15:00Q&A on trading system optimizations
related talks
47mBenchmarking C++, From video games to algorithmic trading
01h 00m“Want fast C++? Know your hardware!"
59mCounting Nanoseconds Microbenchmarking C++ Code
40mLudicrous Speed: Designing For Performance on the JVM
33mReaching Ludicrous Speed
59mPerformance matters - new tricks for old dogs
01h 04mDesign for Performance
01h 38mKeynote: Benchmarking - It's About Time
