Optimizing Code Performance When Branch Prediction Works Against You
By
signa11
An everything bagel for the brain. Substantive, layered, well-seasoned.
Summary
The article discusses techniques for optimizing program performance when branch prediction works against the code, using a financial/trading system example where most transaction requests are abandoned. It explores how to bypass or work around branch predictor limitations to improve performance in scenarios with unpredictable or biased branching patterns.
Key quotes
· 4 pulledA couple of days ago I was thinking about what you can do when the branch predictor is effectively working against you, and thus pessimizing your program instead of optimizing it.
Let's work with something relatively simple & concrete: consider that we want to write some kind of financial system (maybe a trading system) and all of our transaction requests arrive at a certain function before being either (a) sent out to some authoritative server, or (b) abandoned.
The vast majority of our transaction requests end up being abandoned at the last step.
We care A LO
You might also wanna read
Understanding CPU Branch Prediction and Its Impact on Benchmarking
The article discusses how modern processors use branch prediction to execute multiple instructions per cycle, explaining that CPUs have rema
lemire.me·2mo agoDisk Access Outperforms Memory Caching in Modern Hardware Systems
This technical article challenges conventional computer science wisdom by demonstrating that sourcing data directly from disk can be faster
Optimizing .NET APIs for High Throughput: Techniques for 1M Requests Per Minute
Article discusses techniques for designing high-throughput .NET APIs capable of handling 1M requests per minute. It covers horizontal scalin
Reverse-engineering the Intel 8087: A look at microcode and register exchange
A detailed technical deep-dive into the Intel 8087 floating-point co-processor's microcode, specifically examining the register exchange ope

How micro-optimizations in Azure Service Bus SDK paved the way for a smarter redesign
The article discusses how micro-optimizations in the Azure Service Bus SDK led to meaningful design improvements. Rather than advocating for
How Kestra Improved Orchestrator Performance Across 14 Releases: A Year of Performance Engineering
Kestra's engineering team details their year-long performance engineering journey across releases 0.19 to 1.3, treating performance as an on
