Branch Prediction

Noun · Development

Definitions

  1. A CPU optimization that guesses which way a conditional branch (if/else) will go and speculatively executes that path before the condition is evaluated. If the prediction is right (~95% accuracy on modern CPUs), execution continues without delay. If wrong, the speculative work is discarded (pipeline flush penalty of ~15-20 cycles). Sorting data can improve branch prediction accuracy.

    In plain English: The CPU guessing which way an if-statement will go and starting to execute ahead of time, discarding the work if it guessed wrong.

    Example: "Processing a sorted array is faster than unsorted because the branch predictor learns the pattern — the famous Stack Overflow answer about branch prediction."

Related Terms