Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know if a Delphi function is going to be inlined?

When you mark a function as inline, you hint the compiler that this function is a candidate for inlining. The compiler can still decide that it's not a good idea, and ignore it.

  1. Is there a way to see if the function gets inlined or not, without using the disassembler? Is there some compiler warning that I don't know about maybe?

  2. What are the rules for inlining that the compiler uses? Are there constructs that cause a function to never get inlined for example?

like image 647
Wouter van Nifterick Avatar asked Feb 17 '11 15:02

Wouter van Nifterick


People also ask

How do you check if a function is inlined or not?

The decision to inline or not a function is made by compiler. And since it is made by compiler, so YES, it can be made at compile time only. So, if you can see the assembly code by using -S option (with gcc -S produces assembly code), you can see whether your function has been inlined or not.

What does it mean for a function to be inlined?

An inline function is one for which the compiler copies the code from the function definition directly into the code of the calling function rather than creating a separate set of instructions in memory. This eliminates call-linkage overhead and can expose significant optimization opportunities.

Can std :: function be inlined?

An std::function cannot be inlined This overhead can have an impact on the performance if small functions wrapped in std::function are being called very frequently.

Does inline function slow down execution?

Inline function expansion can speed up execution by eliminating function call overhead. This is particularly beneficial for very small functions that are called frequently. Function inlining involves a tradeoff between execution speed and code size, because the code is duplicated at each function call site.


1 Answers

The compiler emits a hint if it can't inline your function. The documentation explains the rules for what can and cannot be inlined.

As for the discretionary decisions that the compiler takes as to whether or not to inline (as opposed to whether or not inlining is possible), they are not documented and can be considered an implementation detail.

I recall that you recently commented on one of my answers to a different question that a particular function was 10 times faster once inlined. Clearly you are interested in inlining but in that particular case I cannot believe such an enormous gain for a function with so many floating point operations. I suspect that inlining is not actually giving you the performance improvements that you think it does.

like image 178
David Heffernan Avatar answered Nov 14 '22 22:11

David Heffernan