[jdom-interest] Possible optimization with ancestry testing?

Steven D. Keens skeens at planetfred.com
Wed Apr 18 13:36:21 PDT 2001


I was thinking that if I could turn off ancestry testing 
in Element's addContent( Element ) method I could get a
nice speed optimization when creating a Document from a
large file.

To test my theory I modified Element.java a little to
be able to turn off ancestry testing and created a test
program that uses SAXBuilder to read an XML file.

I have attached the two files Element.java and test.java.
I was surprised to find that there wasn't a significant
speed increase. Here's the results printed out from one
run of the test program:

	Reading file = test2.xml
	        size = 2595644
	Performing ancestry testing: ON
	Iteration[0] time: 7801 milliseconds
	Iteration[1] time: 7702 milliseconds
	Iteration[2] time: 7721 milliseconds
	Iteration[3] time: 7732 milliseconds
	Iteration[4] time: 7742 milliseconds
	Iteration[5] time: 7741 milliseconds
	Iteration[6] time: 7712 milliseconds
	Iteration[7] time: 7761 milliseconds
	Iteration[8] time: 7772 milliseconds
	Iteration[9] time: 7752 milliseconds
	Time: 77446 milliseconds

	Performing ancestry testing: OFF
	Iteration[0] time: 7571 milliseconds
	Iteration[1] time: 7601 milliseconds
	Iteration[2] time: 7502 milliseconds
	Iteration[3] time: 7511 milliseconds
	Iteration[4] time: 7551 milliseconds
	Iteration[5] time: 7491 milliseconds
	Iteration[6] time: 7582 milliseconds
	Iteration[7] time: 7561 milliseconds
	Iteration[8] time: 7571 milliseconds
	Iteration[9] time: 7562 milliseconds
	Time: 75523 milliseconds

Trying to track down why I realized that the
element being added does not have a parent
because it is a "new Element()" - its parent
is null. So isAncestor() doesn't crawl back up
the tree testing if it is a child of itself.

So it looks like my optimization is not very
important.  But it got me thinking, how useful
is it to test ancestry?  How often is someone
hit with this kind of error and can this test
be moved outside of Element?  Just some thoughts...


--
Steven Keens                mailto:skeens at planetfred.com
PlanetFred Inc.             http://www.planetfred.com
44 Byward Market, Suite 240, Ottawa, ON, K1N 7A2, Canada
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Element.java
Type: application/octet-stream
Size: 64341 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20010418/3945a71d/Element.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.java
Type: application/octet-stream
Size: 2309 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20010418/3945a71d/test.obj


More information about the jdom-interest mailing list