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