c++ - If a function is only called from one place, is it always better to inline it? -


this question has answer here:

if function used in 1 place , profiling shows it's not being inlined, there performance advantage in forcing compiler inline it?

obviously "profile , see" (and in case of function in question, did prove small perf boost). i'm asking out of curiosity -- there performance disadvantages reasonably smart compiler?

no, there notable exceptions. take code example:

void do_something_often(void) {     x++;     if (x == 100000000) {         do_a_lot_of_work();     } } 

let's do_something_often() called , many places. do_a_lot_of_work() called (one out of every 1 hundred million calls). inlining do_a_lot_of_work() do_something_often() doesn't gain anything. since do_something_often() nothing, better if got inlined functions call it, , in rare case need call do_a_lot_of_work(), call out of line. in way, saving function call every time, , saving code bloat @ every call site.


Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -