r/programming • u/chaobang • Aug 22 '26
The unlikely Linux macro
https://rushed-reflections.bearblog.dev/an-unlikely-experiment/Wrote a bit about the `unlikely` and `likely` macros in the Linux codebase. Great little exploration into tiny optimizations that everyone should know more about 😄
188
Upvotes
View all comments
4
u/latkde Aug 23 '26
A related technique is strategic use of
__attribute__((noinline))on helper functions (commonly used as thenoinlinemacro in Linux code). By preventing one function from being inlined, layout of other code may be improved, e.g. if this allows a more important function to be inlined instead.Especially useful on cold helper functions.
Also very useful on functions with multiple callsites to avoid multiple copies of the same code, if I know that overall code density is more important than any benefits that inlining could bring.