Quantitative Trading · Level III · Elective
Low-Latency Programming
The engineering behind high-frequency trading: how memory and caches shape performance, lock-free communication between threads, networking and kernel bypass, measuring latency correctly, and the techniques used in C++ and Rust trading systems.
What you will be able to do
- Explain how caches, memory layout and allocation affect latency.
- Use lock-free queues and thread pinning to keep the critical path predictable.
- Measure latency distributions and apply C++ and Rust low-latency techniques.
Section 1 of 2
Memory and caches
A CPU reads data through a hierarchy of caches. A value in the first-level cache takes about a nanosecond to read; one in main memory can take on the order of a hundred nanoseconds. On a critical path measured in microseconds, a few cache misses matter.
Data laid out contiguously (arrays of structures accessed in order, or structures of arrays for column-wise access) is read efficiently because caches load memory in lines of typically 64 bytes. Pointer-chasing structures such as linked lists and node-based maps scatter data and cause misses.
False sharing happens when two threads write to different variables that sit on the same cache line: each write invalidates the other core's copy. Padding hot variables to separate cache lines removes it.
Keep this in mind: Keep hot data contiguous, avoid pointer chasing and pad against false sharing.
Make the idea stick
Quick checks before you move on.
Quick check 1 of 2 · Memory and caches
Why are contiguous arrays faster than linked lists to iterate?
Quick check 2 of 2 · Memory and caches