Why not mark everything inline?

后端 未结 11 624
长发绾君心
长发绾君心 2020-12-08 13:38

First off, I am not looking for a way to force the compiler to inline the implementation of every function.

To reduce the level of misguided answers make s

11条回答
  •  萌比男神i
    2020-12-08 14:10

    Suppose foo() and bar() both call some helper(). If everything is in one compilation unit, the compiler might choose not to inline helper(), in order to reduce total instruction size. This causes foo() to make a non-inlined function call to helper().

    The compiler doesn't know that a nanosecond improvement to the running time of foo() adds $100/day to your bottom line in expectation. It doesn't know that a performance improvement or degradation of anything outside of foo() has no impact on your bottom line.

    Only you as the programmer know these things (after careful profiling and analysis of course). The decision not to inline bar() is a way of telling the compiler what you know.

提交回复
热议问题