Remove manual branch prediction using __builtin_expect()
A recent discussion on a MR has sparkled interesting question: Are the software developers better at guessing which branch is more likely to happen and does it help with performance? The GCC documentation on __builtin_expect()
says:
In general, you should prefer to use actual profile feedback for this (
-fprofile-arcs
), as programmers are notoriously bad at predicting how their programs actually perform. However, there are applications in which this data is hard to collect.
Turns out that the documentation was right, we are notoriously bad at predicting how our program actually perform.
In the authoritative scenarios in the perflab, the (lo-hi from the last 15) results are:
Scenario | main |
no-expect. |
---|---|---|
1k zones. | 991,710 - 1,001,476 | 985,835 - 992,007 |
1M delegations | 918,952 - 943,186 | 953,149 - 969,046 |
1M RRs | 946,390 - 973,202 | 966,150 - 993,660 |
1M zones | 963,561 - 991,627 | 984,624 - 998,857 |
root zone | 427,566 - 469,889 | 460,026 - 473,576 |
In the recursive scenarios, the branch with disabled __builtin_expect()
surpases the main
branch: