Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Possible ArrayList optimization

xom-interest AT

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT>
  • To: "Bradley S. Huffman" <hip AT>
  • Cc: xom-interest AT
  • Subject: Re: [XOM-interest] Possible ArrayList optimization
  • Date: Sun, 11 May 2003 10:22:59 -0400

At 8:10 PM -0500 5/9/03, Bradley S. Huffman wrote:

I'm assuming you mean spped when building from a SAX source. First in XOM,
get rid of the parent stack, it's not needed, you can call getParent() in

I don't see how that would work. getParent() returns null before I've added it to the parent. That's why I need the parent stack. I could move more work into endElement() but I'm not sure how that would help.

Also I think you can add attributes and namespace
declarations in one loop instead of two.

Good idea. Probably a small improvement, but couldn't hurt.

Now obviously, what would be ideal is to know the number of children at
element creation, but that's not going to happen with SAX. So here's a
wild idea, have a large buffer to hold newly created nodes. In all node
creation methods (startElement, comment, flush*(), etc.) buffer the newly
created node but **don't** add it to the current parent (as JDOM and XOM
currently do), instead just increment the child count of the current parent
(either find some way to use the parent to hold this info, or stack it).
Finally in endElement(...) create the children list in the current
parent according to the current child count and move nodes from the buffer
to the parent. This should eliminate most unnecessary reallocation and
copying of nodes. Hmmm, guess it would also eliminate the wasted overhead :)

Sounds pretty complex. Right now my tests are showing this is not where my hot spots are during building. Verification and parsing overhead just swamp this. More on that shortly.

Elliotte Rusty Harold
elharo AT
Processing XML with Java (Addison-Wesley, 2002)

Archive powered by MHonArc 2.6.24.

Top of Page