-
On the use of inline
I have read the following statement (partial quote):
"A reasonable rule of thumb is to not put inline at functions that have more than 3 lines of code in them."
Does this rule of thumb apply if the three lines call a massive chunk of code, e.g., from a library?
-
> Does this rule of thumb apply if the three lines call a massive chunk of code, e.g., from a library?
No, it applies to the inline function only.
The naive interpretation of inline is that the body of the function is copy/pasted into the place where you call this function. The thinking goes that if your inline function is large, then all you end up with is executable code bloat. This might make the code worse, if the inlined function is called frequently. Instead of 1 copy of the function residing in cache and being called, you have multiple clones which need to be fetched on demand.
It depends on how well your optimiser handles the code inserted into the call site, and whether the compiler itself treats inline in some kind of advisory way and makes choices for you.