You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by "Lander, Kris - NA US HQ Delray" <KL...@mytravelco.com> on 2002/12/12 17:28:01 UTC

NodeList Performance Issues

Hello to all on the list, this is my first post and I hope someone will be
able to shed some light on my problem.

I have come across some strange performance when using Xalan and a NodeList
in an iteration. Please take a look at the following snippets of code.

Version 1

NodeList categoryNodes = categoryResponse.getCategoryList();
final int numOfCategories = categoryNodes.getLength();

for (int i = 0; i < numOfCategories; i++) {

	long time = System.currentTimeMillis();
      Node categoryNode = categoryNodes.item(i);
      g_logger.debug("Time taken to clone " + i + " : " +
(System.currentTimeMillis() - time));
	
	time = System.currentTimeMillis();
	CategoryBean bean = new CategoryBean( categoryNode,
bookingBean.isAirfareRequested(),
      					        isPrincess,
bookingBean.getNumberOfPax());
	g_logger.debug("Time taken to construct " + i + " : " +
(System.currentTimeMillis() - time));  

}

Version 2

NodeList categoryNodes = categoryResponse.getCategoryList();
final int numOfCategories = categoryNodes.getLength();

for (int i = 0; i < numOfCategories; i++) {

	long time = System.currentTimeMillis();
	Node clonedCategoryNode = categoryNodes.item(i).cloneNode(true); 
      g_logger.debug("Time taken to clone " + i + " : " +
(System.currentTimeMillis() - time));
      
	time = System.currentTimeMillis();
	CategoryBean bean = new CategoryBean( cloneNode,
bookingBean.isAirfareRequested(),
      					        isPrincess,
bookingBean.getNumberOfPax());
	g_logger.debug("Time taken to construct " + i + " : " +
(System.currentTimeMillis() - time));  


}

In the first version you'll notice I'm I'm looping through each Node item in
the node list and passing it to the Bean constructor.

In the second version I'm creating a clone of each Node item in the list and
passing the clone to the Bean constructor.

Now look at these execution times.

Version 1

Loop Iteration		Time taken to get item from list		Take
taken to complete Constructor

1				0ms
130ms
2				0ms
220ms
3				0ms
301ms
4				0ms
391ms
5				0ms
500ms
6				0ms
602ms
7				0ms
691ms
8				0ms
781ms
9				0ms
812ms
10				0ms
981ms

Version 2

Loop Iteration		Time taken to clone item from list		Take
taken to complete Constructor

1				10ms
90ms
2				10ms
70ms
3				10ms
70ms
4				10ms
80ms
5				10ms
70ms
6				10ms
61ms
7				10ms
80ms
8				10ms
70ms
9				10ms
70ms
10				10ms
80ms


Does anyone have any bright idea about why cloning the XML nodes actually
makes execution faster? And why in the first snippet of code the execution
time gets longer for every iteration? I'm guessing that it has something to
do with how the NodeList is implemented. Is there some just-in-time stragegy
employed with NodeList?

Any insight will be much appreciated.

-Kris