branch misprediction
also: branch miss, prediction miss, pipeline flush
A CPU performance issue where the processor incorrectly predicts which direction a conditional instruction will take, forcing it to discard speculative work and restart. This causes a pipeline stall and reduces execution efficiency.
Modern CPUs use branch prediction to guess whether a conditional statement (like an if) will be true or false, so they can speculatively execute instructions down the predicted path before the condition is fully evaluated. When the prediction is wrong, the CPU must flush the speculatively executed instructions from its pipeline and start over, wasting clock cycles.
Branch mispredictions are particularly costly in tight loops or data-dependent conditions where the pattern is unpredictable. For example, a loop that filters an array based on a condition may mispredict frequently if elements pass the condition randomly, causing the CPU to repeatedly throw away work.
Performance-conscious developers can reduce mispredictions by writing code with predictable branching patterns, using techniques like loop unrolling or conditional moves (cmov) instead of jumps. Modern CPUs employ sophisticated prediction algorithms (tournament predictors, neural-based predictors) to minimize these misses, but unpredictable branches remain a significant bottleneck in CPU performance.