Why is not inlining that bad?

Walter Bright newshound1 at digitalmars.com
Mon Oct 8 02:42:28 PDT 2007


Janice Caron wrote:
> Forgive me if this is a dumb question, but in other threads I've seen
> it argued that dereferencing an address from a register offset is not
> something that anyone needs to be worried about, and that array
> accesses are so fast that no one need worry about them, etc.
> 
> This being the case, why is anyone worried about the overhead of a
> function call? It's just a memory write and a few registers changing,
> surely? It's not a massively expensive operation like a thread switch
> or anything, so why worry?
> 
> If the hardware does memory caching, the return may not even need a
> memory access.
> 
> What am I missing? Is it just that D initializes all its local
> variables as part of calling a function? If so, there are plenty of
> ways around that.

Inlining a function, besides getting rid of the function call/return 
code, which can be significant, also enables interprocedural 
optimizations: register assignment, common subexpressions, constant 
folding, etc. It can result in dramatically fewer instructions being 
executed. Besides, it is more code memory cache friendly.



More information about the Digitalmars-d mailing list