intermediate · speculation
Why Unpredictable Branches Hurt
Why can an unpredictable branch cost far more than the work inside it?
Practical scenario
A filter loop over 50 million records is slower than a colleague expects. The body is a comparison and an add. Someone suggests the comparison must be expensive.
What it tests
- • Understanding of why a pipelined CPU must speculate at all
- • Knowledge that the misprediction cost scales with pipeline depth
- • Whether the candidate connects branch predictability to data, not just code
Lessons behind this question
Branch Prediction: Guessing Well Enough to MatterMisprediction: What a Wrong Guess CostsControl Hazards: The CPU Does Not Know Where You Are GoingSpeculative Execution: Doing Work Before You Know You Need ItBranchless Code: A Trade, Not an UpgradePipelining: Throughput Without Making Anything Faster