When developing C++ programs with clang or gcc inlining metrics are taken by default so how a user can choose the inlining parameters like the max size of the inlinee method or the container size for example to optimize for the best his program? Does a programmer have to look for example to the size of the produced executable? number of virtual methods? how inlining metrics should be taken?
Asked
Active
Viewed 73 times
0
-
2These days in most situations its best to let the compiler do its job and avoid manual intervention unless absolutely necessary (meaning you profiled and found a need to optimize). – drescherjm Aug 29 '18 at 16:04
-
2"Does a programmer have to look for example to the size of the produced executable?" if you dont know then most likely no. Size of the executable can be important when you target a system with scarce ressources – 463035818_is_not_an_ai Aug 29 '18 at 16:07
-
Normally, you do fine by giving the compiler the appropriate compiler flags, e. g. [GCC](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html): `-O3` (speed) or `-Os` (size), possibly `-Ofast` or `-Og` as well. – Aconcagua Aug 29 '18 at 16:11
-
1If you have an issue, rather take the effort to *profile* your application. Chances (less small than you think probably) are that the bottle neck will be at some totally different location you didn't even have in mind before. Then optimise *this specific* function (maybe even on assembler level). – Aconcagua Aug 29 '18 at 16:17
-
@user463035818 From what i now inlining is only performed on small functions ,if program size is not important why we don't inline big functions?can we always trust the compiler to find the right combination between the size and the speed of a program? – Achrouf Abdenour Aug 29 '18 at 20:10
-
well, my comment was a bit sloppy. Of course the size of the executable does matter, but the details of all the trade-offs are that complex that you cannot trust a programmer to find the right combination in his lifetime. Note that for example gcc has the [-Os flag to optimize for size](https://stackoverflow.com/questions/19689014/gcc-difference-between-o3-and-os)(but not for performance) – 463035818_is_not_an_ai Aug 29 '18 at 20:26
-
Let say that we do an aggressive method inlining and the size will be 3 times or more than usually?how do this will affect the performance of the program if we run it in desktop ,iphone or Android where these days we have 4 GB up to 32 gb of ram,if aggressive inlining is benefit in all situations why we don't compile programs every time with the -O3 flag for exemple rather than using the -O2 flag wich is the most commun by default. – Achrouf Abdenour Aug 30 '18 at 10:25
1 Answers
1
If you have a need to spend time with micro-optimization, output the assembly and see if your function is inlined within the contexts you use it. There are online tools that does this with multiple versions of gcc and clang. You will get the hang of it after a few experiments.

nurettin
- 11,090
- 5
- 65
- 85