[jdom-interest] Presences of Namespace dramatically slows
tim at peierls.net
tim at peierls.net
Thu Apr 12 13:23:06 PDT 2001
Tim Peierls <mailto:tim at peierls.net> wrote:
> > On a related note, shouldn't availableNamespaces be declared as a
> > List rather than a LinkedList? It doesn't make use of any special
> > linked list capabilities, does it?
To which Jason Hunter <mailto:jhunter at collab.net> responded:
> Since it's a private variable it really doesn't matter.
> It's LinkedList because for performance I make some addFirst() calls
> which only exist on LinkedList.
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). Was your decision
to use addFirst() based on an empirical performance difference
between these methods?
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.
> This is why I love open source. You never know
> who's going to come out of the woodwork and
> identify a bug.
Funny, it didn't seem like woodwork when I left it. :-)
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. The reason you added the test
was to avoid unnecessary calls to remove, but you are no longer
calling remove. The huge time blowup you were seeing was from
calls to Object.equals(), as each item on availableNamespaces
was tested for equality with the argument List. These tests
were futile, of course, but they sure took a lot of time.
I know, nitpicking. Can't help it.
More information about the jdom-interest