With modern compilers, does declaring a function inline have any effect on performance anymore?
That is, faced with the option of defining a function inline in the header or in the source file, is there any difference between the two?
In this SO question, When to use inline function and when not to use it?, the accepted answer gives several reasons.
An excerpt:
do:
- very small functions are good candidates for
inline
: faster code and smaller executables (more chances to stay in the code cache) - the function is small and called very often
don't:
- large functions: leads to larger executables, which significantly impairs performance regardless of the faster execution that results from the calling overhead
The advice is from 7 years ago, and I've read that these days the inline word is ignored, and the compiler decides what to inline.
Questions:
- Is the above advice still relevant?
- To what extent does defining a function inline have any effect (other than to prevent multiple definition linker issues)?
- What reasons do I have to inline a function these days?