Guess Fast Or Wait!



Imagine you're in an unfamiliar city, trying to find a place to stay. You decide to use your phone to navigate. Since you have a good sense of direction, you already start walking, while looking up the way on your phone.

If you guessed the direction correctly, you didn't waste any time waiting for the result, and can continue on your way. If your guess was wrong, you have to turn around.

A modern CPU does this as well: When its course of action depends on a result it would have to wait for, it makes an educated guess and continues along this path. This is called speculative execution. If the guess was wrong, the CPU has to discard all the actions it has done in error. It did not waste any time though, as it would have spent the time waiting instead. However, if the guess turns out to be correct, the CPU just gained a little speed boost.