Consider the following situation:
You have a macro doing something very often throughout the whole code. (For example some Exception handling)
This macro will usually do very little, but periodically, certain circumstances arise such that the macro must do a lot more...
This could be easily implemented using conditional branches to choose if the complex or the simple code is needed, and branch if the complex code is needed... BUT this may lead to the following grave performance issue:
- Many modern branch predictors use the same prediction structures for multiple branches, such that the data collected from other branches affects the prediction of every single branch! Thus, the overwhelming count of branches not taken most of the time may "confuse" the branch predictor, such that it will make horrible predictions for the other branches!
How can I get around this issue?
Note that, because the complex code is called very very seldomly, I really don't care about the efficiency in that case!
(A starting point for research may be: how do languages like java get around that issue?)