[jdom-interest] AttributeList performance

Elliotte Harold elharo at metalab.unc.edu
Sun Apr 24 09:23:05 PDT 2005

Martin Schulz wrote:

> We now face the choice to
> a) speed up JDOM internally
> b) subclass AttributeList and implement it more efficiently
> c) build a HashMap from the AttributeList externally
> d) not use Element attributes for this purpose

I suggest option b.

> Being naive about XML, my first question is whether the order of
> attributes is either significant or within JDOM guaranteed to be stable
> as part of any API contract, or is it considered a 'nice-to-have'?

The order is absolutely insignificant and in no way guaranteed. This is 
an XML-level issue, not a JDOM one.

> There might well be an implementation trade-off where the current 
> default (array of 5 Attributes)
> is the better choice compared to adding a datastructure with a bigger 
> footprint, so I'd
> be curious about what others might deem appropriate in this situation.

My strong suspicion is that in the more normal use cases where elements 
have half a dozen attributes at most, or less, ArrayLists are much more 
efficient than HashMaps. You may have crossed the threshold where the 
bigger constant factor of a HashMap vs. a list makes the HashMap faster, 
so a custom subclass might make sense for you. However, I doubt it makes 
sense for the majority of users.

Elliotte Rusty Harold  elharo at metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!

More information about the jdom-interest mailing list