On Sun, Mar 17, 2002 at 10:06:46PM -0800, Andy Ross wrote:
> David Megginson wrote:
> > The biggest surprise was that inlining methods made things slower, not
> > faster, in most cases (there were a couple of exceptions).  That may
> > be a quirk of G++'s code generation, but it's probably worth
> > considering -- I had inlined much of the infrastructure to try to
> > speed things up, but then put it back out of line again piece by
> > piece.
> 
> It's probably not a quirk.  Inlining actually helps very little except
> for VERY small functions.  It used to be that a function call was slow
> -- you had to spill a bunch of registers and a return value onto the
> stack, and then clean them up later.  But modern processors can, for
> the most part, stick all that mess into into a few extra pipeline
> stages.
> 
> And all the extra code takes up extra cache lines, that are critical
> to performance on modern memories.  So naively inlined code can
> actually be slower.
> 
This was discussed on lkml a while ago, and the consensus was that
optimising for cache usage was more important than almost anything
else on a modern chip - using -Os rather than -O2/3 can be better,
at least for performance critical code, to minimise the cache
footprint.

As for inline functions, they're not as much of a performance
improvement as you might think, because modern compilers are very
good at minimising the cost of function calls. This was also
discussed on lkml . . . 

Cutting and pasting from the lkml thread:
------------------------------------------------------------
The first patch should be against Documentation/CodingStyle.
What are we trying to achieve here?  What are the guidelines
for when-to and when-to-not?  I'd say:

- If a function has a single call site and is static then it
  is always correct to inline.

- If a function is very small (20-30 bytes) then inlining
  is correct even if it has many call sites.

- If a function is less-small, and has only one or two
  *commonly called* call sites, then inlining is OK.

- If a function is a leaf function, then it is more inlinable
  than a function which makes another function call.
------------------------------------------------------------

Not sure how this translates to C++ inlining (I'm a C-only man at
present), but it probably isn't too different.

Simon

-- 
PGP public key Id 0x144A991C, or ftp://bg77.anu.edu.au/pub/himi/himi.asc
(crappy) Homepage: http://bg77.anu.edu.au
doe #237 (see http://www.lemuria.org/DeCSS) 
My DeCSS mirror: ftp://bg77.anu.edu.au/pub/mirrors/css/ 

Attachment: msg04155/pgp00000.pgp
Description: PGP signature

Reply via email to