What does 'inline' mean?

Patrick Schluter Patrick.Schluter at bbox.fr
Tue Jun 9 14:03:29 UTC 2020


On Tuesday, 9 June 2020 at 09:29:47 UTC, Walter Bright wrote:
> On 6/8/2020 7:09 AM, Manu wrote:
>> [...]
> The C/C++ inline semantics revolve around the mechanics of .h 
> files because it doesn't have modules. These reasons are 
> irrelevant for D.
>
> > [...]
>
> For .h files, sure. Why for D, though?
>
>> [...]
>
> Why are 0 or N copies fine, but 1 is not?
>
>
>> [...]
>
> Why? What problem are you solving?
>
>
>> [...]
>
> I know I'm being boring, but why is it important? Also, check 
> out -gc-sections:
>
> https://gcc.gnu.org/onlinedocs/gnat_ugn/Compilation-options.html
>
> Which is a general solution, not a kludge.
>
>
>> [...]
>
> Executables (on virtual memory systems) are not loaded into 
> memory and then run. They are memory-mapped into memory, and 
> then pages are read off of disk on demand. Unmapped code 
> consumes neither memory nor resources.
>
>
>> [...]
>
> The default, and pragma(inline,true) are sufficient for all use 
> cases except which ones?
>
>> [...]
>
> You won't get a sea of warnings unless you put 
> pragma(inline,true) on a sea of functions that can't be inlined.
>
>> [...]
>
> Why?
>
>
>> [...]
>
> Inlining is 100% about optimization.

You forgot the case where it is about pessimization :-)

The thing with inlining is that it often looks good in benchmarks 
but not that good in whole applications because of the impact it 
can have on code size.
In my modest experience, the worse offenders where always the 
people that insisted very much on forcing inlining. I had once a 
colleague that had put inlines everywhere in his lib without 
realizing that nesting inlined functions has a multiplying 
effect. I calculated the equivalent in line of codes that were 
inlined and it was around 6000, for a library that had only 13000 
lines to begin with.
The effect on the instruction cache was huge.

>
>
>> [...]
>
> Optimizing things that don't matter is wasting your valuable 
> time. Optimizing things that are more effectively and 
> thoroughly done with the linker (-gc-sections) - it's like 
> chipping wood with a hatchet rather than a woodchipper.



More information about the Digitalmars-d mailing list