[jdom-interest] Presences of Namespace dramatically slowsSAXBuilder

Jason Hunter jhunter at collab.net
Thu Apr 12 13:51:52 PDT 2001

> The 1.3.1-rc1 sources -- and a quick test program -- suggest that
> LinkedList.addFirst(obj) is not a whole lot faster than the
> LinkedList implementation of List.add(0, obj). 

Considering it's a private variable, what's wrong with this approach if
it's a little faster?

> Was your decision
> to use addFirst() based on an empirical performance difference
> between these methods?

Honestly, I wasn't thinking about a perf gain, I was thinking I prefer
addFirst() to add(0, obj) for readability.  At this point the goal is to
make everything work rock solid and solve big performance issues, not
squeeze out drops of performance.

> More to the point, Joseph Bowbeer has already asked (on this list)
> whether it might not be more efficient to use ArrayList instead of
> LinkedList. Instead of addFirst() and iterating forward, you could
> add(), i.e., at the end, and use ListIterator to iterate backwards.

Since it's a private var we can tweak that at any point in time.

> I noticed that your recent fix -- removeAll instead of remove in
> SAXHandler.java -- left in the test for empty list, which is
> now almost certainly unnecessary. 

Actually, I think it's still useful.  If you look at the
foo.removeAll(bar) implementation what it does is iterate over every obj
in foo and for each checks if it exists in bar, and if so removes it
from foo.  So if foo has 1000 items and bar is empty you still walk each
item!  Considering 99.9% of the time in this JDOM use case the bar list
will be empty, the pre-check is a great optimization.

More information about the jdom-interest mailing list