Jump to content
Der schöne Günther

What are the correct settings for "Code inlining control"?

Recommended Posts

Under Project > Options > Building > Delphi Compiler > Compiling we have the project-widde option Code inlining control.

image.png.d65e37ecca8bb080e484b3ce7e8b2460.png

 

It can also be set in code with something like {$INLINE ON|OFF|AUTO}.

 

How inlining works and when the compiler cannot inline methods is explained in Delphi's Docwiki under Calling Procedures and Functions.

It states that the default project setting is that inlining is set to ON which I found to be correct. However, the Help page Compiling states that OFF is the default setting.

 

I am not sure what is the right choice for debug and for release builds. Wouldn't it be

  1. Set Inlining to OFF for all debug builds
  2. Set Inlining to AUTO for all release builds

 

Or is there no universal recommendation and it depends on the project and its requirements?

 

Many thanks in advance.

Share this post


Link to post

You might want to turn inlining on for debug builds if what you are trying to debug might be releated to inlining. But in most cases I would also turn it off because it is really annoying if you can't step into a function because it was inlined.

  • Like 1

Share this post


Link to post

I would never ever turn it to AUTO because that causes the compiler to inline every function that has a size of 32 bytes or less.

The inliner of the Delphi compiler is really bad and while one might think that inlining code usually makes stuff better/faster that is not the case and usually (decent) library developers know where to put inline and where not to put inline.

  • Like 3

Share this post


Link to post
4 hours ago, Stefan Glienke said:

I would never ever turn it to AUTO because that causes the compiler to inline every function that has a size of 32 bytes or less.

The inliner of the Delphi compiler is really bad and while one might think that inlining code usually makes stuff better/faster that is not the case and usually (decent) library developers know where to put inline and where not to put inline.

Interesting. I certainly would have expected that the (minor) overhead of a function call would cost more than just putting it inline and if the inline code is the same size or smaller, it would make sense to do it that way as a default. Can you point me to a resource that investigates this issue and shows why this is wrong thinking? I'm not saying you are wrong, I just want to learn more.

Share this post


Link to post

It is from my own experience and analyzing generated code in several different scenarios.

I have seen the inliner generating like x times more instructions including ridiculous amounts of mov instructions to and from the stack just to inline a harmless little function which it could way better if the inliner and the register allocator would not have been absolute trash.

 

Plus there are "funny" little issues like this: https://quality.embarcadero.com/browse/RSP-30930

 

Here is an example where inlining creates some ridiculous amount of instructions: https://quality.embarcadero.com/browse/RSP-31720 (which is not caused by auto but the fact that the getter is being marked as inline)

Edited by Stefan Glienke
  • Like 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×