[Development] To "inline" or not (Was " Mutex future directions")
Olivier Goffart
olivier at woboq.com
Tue May 22 13:55:06 CEST 2012
On Tuesday 22 May 2012 07:08:34 Atlant Schmidt wrote:
> Folks:
>
> There's been a lot of discussion recently regarding whether
> or not Qt functions (specifically, interlocking functions)
> should be declared "inline" or not.
>
> But in fact, isn't this much ado about nothing? If I
> understand current compiler technology, when one declares
> a function "inline", that's nothing more than a hint to
> the compiler. (At least at high optimization settings),
> the compiler can choose to ignore you and compile your
> function as an ordinary out-of-line function. It can also
> chose to elevate any ordinary function to inline if it
> chooses. (Isn't "tail-folding" a common example of this?)
>
> We can discuss this 'til the cows come home, but nowadays,
> how much control can we really assert / do we really want
> to assert over this?
>
> Aren't we supposed to be Relegating the Important Stuff
> to the Compilers?
What you write there is true for code within the same object.
But here we are talking about code used between libraries and about binary
compatibility.
We have to choose between letting the compiler inline, or not.
If we let the compiler the possibility to inline the code, that means that the
code build with Qt 5.0 will include that inline code in its binary.
Which means that if we want change the internal in Qt 5.x, we still need to be
aware that the old inlined code can still be run.
So we need to be very careful about allowing the compiler to inline, because
that restricts us a lot in what we can change from version to version.
Then, we can disallow the compiler to inline by not putting the code in the
header.
Then we loose in performance. Inlining safe performance not only because it
saves the overhead of a function call, but mainly because it allows the
compiler to do more analysis of the code around, allowing it to perform a lot
more of optimization.
It is also not binary compatible to change the inlineness of a function:
With Linux we compile with -fvisibility-inlines-hidden, which means inlined
symbol are not exported. So if we inline a method, it stops being exported.
And binaries compiled with old Qt stop working.
--
Olivier
Woboq - Qt services and support - http://woboq.com
More information about the Development
mailing list