The Artima Developer Community
Sponsored Link

Code size affects locality of reference.



This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Code size affects locality of reference.

Posted by Jonathan Brumley on 06 Jul 1998, 3:26 PM

> > The optimization lore list addresses the major speed weaknesses
> > of current JVMs. However, if your JVM supports a JIT then the
> > second point about making classes large to avoid method call
> > overhead can actually slow things down. Larger methods mean
> > more simultaneously active local variables and this can create
> > a situation where not as many locals are assigned to native
> > hardware registers. Depending upon the program the extra loading
> > and storing of unassigned locals can generate more overhead
> > than that the method calls for an alternative method partitioned
> > version.

> Remember that calling a method means specifically storing and
> then loading registers on the stack. You don't save register
> swapping by calling methods instead of inlining work. You do, of
> course, get code readability, but from a pure performance point
> of view, there shouldn't be much difference, or in the worst case
> calling methods will be slower.

> Chris Smith
> OU

Code size affects the locality of reference of your program. When your locality of reference gets wide, then your program starts getting lots of cache misses, and can slow down dramatically.

Method invocation doesn't always involve saving and restoring registers. Depends on the hardware architecture. Some hardware architectures (i.e. Sparc) use register windowing.

Inlining doesn't affect readability of the code, unless you're saying that using the word "final" clutters up your code.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us