New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce branching on a common case #11074
base: unstable
Are you sure you want to change the base?
Reduce branching on a common case #11074
Conversation
I usually object this kind of optimization changes unless we prove they actually make a difference. that's true about using switch-case vs if-else, grouping multiple if's with a common condition into a nested one, and also about a computation that isn't always needed (or is placed inside a loop and can be moved out) testing it: https://godbolt.org/z/TzYxePKTd
indeed in yours it doesn't do
i'd like to see a benchmark that proves it actually does something |
First I think the code is more readable this way. |
i agree with both statements. but i'm arguing that in some cases the compiler would have already done these on it's own (grouping similar conditions and moving computation around), and that without using __builtin_expect we can't be sure the compiler will comply to the changes we make. in your case, with the one specific compiler i checked, it seems it did! but i'm generally against such micro optimizations without measuring a consistent improvement. |
|
When the prefix is
":"
code takes a long path through all the branches and calculates theOBJ_SHARED_HDR_STRLEN
for nothing.