[jdom-interest] Re: New realease, Text class... Arghh
dms at sosnoski.com
Wed Jan 9 18:52:23 PST 2002
Using indexed lookup is not necessarily a good idea with the (beta)
released version of JDOM. This code returns a linked list (PartialList),
so indexing can get very expensive - it requires chaining through the
list on every access. If you *know* you're working with an ArrayList or
equivalent indexing through the elements is great. Otherwise it's safer
to use an Iterator, especially since object creation overhead is pretty
low for Hot Spot JVMs.
If the PartialList code is replaced for the next release of JDOM it
should show some nice performance improvements. Methods of the type you
mentioned (attributeCount(), nodeCount(), getAttribute(int), and
getContent(int)) would also help, since they eliminate the need for
lists to be created just so something can be returned - I pointed out a
while ago that JDOM memory usage actually grows by about a third in my
tests after a document is walked for the first time. This is because
when you ask for the attributes of an element that doesn't have any yet
JDOM creates a new list. Being able to access the attributes and content
directly would avoid this type of issue.
dom4j provides these methods, by the way, which is one of the reasons it
generally gives better performance than the current JDOM.
Bradley S. Huffman wrote:
>Dennis Sosnoski writes:
>>I'm glad to see that JDOM is adding these methods
>May add these methods, I just hack and submit ;)
>>I'm not sure it's entirely fair to say "those test have a problem",
>>considering that I used what appeared to be the best methods available
>>in the released version of the code. ;-)
>It wasn't about which JDOM methods you used, but about using a Iterator
>to trasverse a List inside a recursive method (BenchJDOM.walkElement).
>This caused the test (not JDOM) to added a additional time pentaliy.
>Granted, the change to using a for loop still doesn't give JDOM the best
>times, but the test should be as neutral as possible.
>In all fairness I would of used a Iterator myself and not given it a second
>thought. But now after seeing a good example of how it can affected things,
>I've made a mental note to always use a for loop and List.get(int) unless
>I need the functionality of remove.
>Ahhh, the joys of objects.
More information about the jdom-interest