DIP56 Provide pragma to control function inlining

Manu turkeyman at gmail.com
Mon Feb 24 08:58:07 PST 2014


On 24 February 2014 07:53, Walter Bright <newshound2 at digitalmars.com> wrote:

>
>  With error - yo get a huge advantage - an _instant_ feedback that it
>> doesn't do
>> what you want it to do. Otherwise it gets the extra pleasure of running
>> disassembler to pinpoint your favorite call sites or observing that your
>> profiler shows the same awful stats.
>>
>
> My point is you're going to have to look at the asm of the top functions
> on the profiler stats anyway, or you're wasting your time trying to
> optimize the code. (Speaking from considerable experience doing that.)
> There's a heluva lot more to optimizing effectively than inlining, and it
> takes some back-and-forth tweaking source code and looking at the
> assembler. I gave some examples of that above.
>

For those interested, in my experience, the value of inlining is rarely
related to eliminating the cost of the function call. call and ret have
virtually no impact on performance on any architecture I've used.
The main value is that it eliminates stuffing around with parameter lists,
and managing save registers. Also, some argument types can't pass in
registers, which means they pass through memory, and memory access should
be treated no differently from the hard drive in realtime code ;) .. The
worst case is a write followed by an immediate read (non-register argument,
or save register value); some architectures stall waiting for the full
flush before they can read it back. It's called a Load-Hit-Store hazard,
and it's the most expensive low level hazard short of an L2 miss.
But the most important use by far is that you can control which functions
are leaf functions. Leaf functions (functions that don't allocate a stack
frame at all) are critical for good performance. Any small helper functions
you call MUST be inlined, or your function is no longer eligible to be a
leaf function.

I agree that inline should be a hint (a STRONG hint, not like 'inline' in
C, more like __force_inline, perhaps stronger), but I'd like it if I
received a warning when it failed for whatever reason. I don't want it to
stop compiling, but a nice notification that I should look into it, and the
ability to disable/silence the warning if I can't/don't intend to.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140225/e527e6f4/attachment-0001.html>


More information about the Digitalmars-d mailing list