Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Small improvements

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: François Beausoleil <fbeausoleil AT ftml.net>
  • Cc: xom-interest <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] Small improvements
  • Date: Sun, 28 Nov 2004 10:53:58 -0500

Hi !

Elliotte Harold wrote:
Wolfgang Hoschek wrote:
12% speedup in ParentNode.java for changing the static declaration of childen from a List to an ArrayList (which it is anyway):
ParentNode.java:

ArrayList children;
//List children;


That's easy enough to do, and doesn't really harm anything. It's a minor code smell at worst. However in my tests this had no noticeable effect. Can anyone explain why this might have such a dramatic effect? i.e is there any theoretical reason to believe this is a good idea? Is this likely to be very different from one VM to another? Is this something that might make a big difference in 1.5 and not 1.4? or the server VM and not the client?

You all probably already know that, but List is an interface, whereas ArrayList is a concrete class. The way the JVM maps functions to memory makes access to concrete methods an O(1) operation, whereas access to an interface methods is O(n/2) on average, where n is the number of methods defined in the concrete class and all parent classes.

Why the difference ? All concrete classes have their methods at the same offset from the classes' base address. This is an artefact of the compilation method, if I remember correctly. On the other hand, when interface methods are thrown in, the compiler cannot map these to always the same offset, because the interface might be implemented by different concrete classes, which means that the methods will not always be at the same offset.

Anyway, I wasn't trying to offend anyone here. Forgive me if you already knew all of that.

Have a nice day !
François





Archive powered by MHonArc 2.6.24.

Top of Page