Branch prediction
Every time a program hits an 'if' or a loop, the processor faces a fork: which instruction comes next depends on a comparison that may not be finished yet. Rather than stall and wait, a branch predictor gambles — it guesses which way the branch will go and charges ahead speculatively, like a delivery driver who picks a route before the dispatcher has confirmed the address, betting on the most likely answer.
A good predictor learns patterns: a loop that runs 1000 times is 'taken' 999 times, so it predicts 'taken' and is right 99.9% of the time. Modern predictors use tables of branch history and reach 95–99% accuracy. When the guess is wrong, the processor must throw away all the speculative work and restart from the correct path — a misprediction penalty of 10–20 cycles. Branch prediction is so central that flaws in speculative execution caused the famous Spectre and Meltdown security vulnerabilities.
Spectre/Meltdown (2018) showed that speculative execution can leak secret data through cache timing side-channels — a reminder that performance tricks can have security costs.