Semi-static Conditions in Low-latency C++ for High Frequency Trading: Better than Branch Prediction Hints
Paul Alexander Bilokon, Maximilian Lucuta, Erez Shermer

TL;DR
This paper introduces semi-static conditions in C++ that allow dynamic modification of branch directions at runtime, outperforming traditional branch prediction hints in low-latency, high-frequency trading scenarios.
Contribution
It presents a novel language construct enabling runtime branch direction changes by modifying assembly code, surpassing existing compiler hints like [[likely]] and [[unlikely]].
Findings
Semi-static conditions outperform traditional branch prediction hints in specific scenarios.
The approach enhances performance in high-frequency trading applications.
Considerations of portability, syntax, and security were addressed during development.
Abstract
Conditional branches pose a challenge for code optimisation, particularly in low latency settings. For better performance, processors leverage dedicated hardware to predict the outcome of a branch and execute the following instructions speculatively, a powerful optimisation. Modern branch predictors employ sophisticated algorithms and heuristics that utilise historical data and patterns to make predictions, and often, are extremely effective at doing so. Consequently, programmers may inadvertently underestimate the cost of misprediction when benchmarking code with synthetic data that is either too short or too predictable. While eliminating branches may not always be feasible, C++20 introduced the [[likely]] and [[unlikely]] attributes that enable the compiler to perform spot optimisations on assembly code associated with likely execution paths. Can we do better than this? This work…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsParallel Computing and Optimization Techniques · Distributed and Parallel Computing Systems · Advanced Data Storage Technologies
