You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Michael Smith <ms...@xn.com.au> on 2001/02/05 05:46:49 UTC

Reducing object creation in xalan2 with DOM use

Hi,

Here's a patch for DOM2Helper.java which has a noticable impact on
object creation (and speed) when giving xalan2 a DOM tree as input.

For some reason, this code was throwing and catching a
ClassCastException for every call to the function. This was leading to
several thousand useless objects being created every second, for
something which is by no means an error. 

This could perhaps have the second check taken out (so we only do one
instanceof call) - I'm not sure what's going on internally, though, so I
haven't done this. The speed hit of these two checks is nothing compared
to the cost of creating an exception object, and then throwing and
catching it. We saw a noticable speedup with this. It also seems much
more sensible to me.

Michael

p.s. please also mail any replies directly to me, I'm not currently on
the xalan list. Thanks.




--- DOM2Helper.java	Sat Jan 13 10:21:47 2001
+++ DOM2Helper.java.new	Mon Feb  5 15:39:32 2001
@@ -273,14 +273,14 @@
 
     // Assume first that the nodes are DTM nodes, since discovering
node 
     // order is massivly faster for the DTM.
-    try
+    if(node1 instanceof DOMOrder && node2 instanceof DOMOrder)
     {
       int index1 = ((DOMOrder) node1).getUid();
       int index2 = ((DOMOrder) node2).getUid();
 
       return index1 <= index2;
     }
-    catch (ClassCastException cce)
+    else
     {
 
       // isNodeAfter will return true if node is after countedNode