Bypassing the Branch Predictor
7 days ago
- #low-latency
- #branch-prediction
- #performance-optimization
- Branch predictor can pessimize performance when it predicts the wrong path, especially in critical systems like financial trading.
- Modern x86 processors ignore branch prediction hints, making low-level solutions like instruction prefixes ineffective.
- C++20's [[likely]] and [[unlikely]] attributes do not influence CPU branch prediction but can reorder code paths for optimization.
- A higher-level solution involves priming the branch predictor with mocked transactions to favor the critical path.
- Network cards can efficiently filter out mocked transactions, minimizing overhead on real transactions.
- Using mocked transactions can lead to significant performance improvements, as demonstrated by a 5 microsecond speed-up in trading systems.