United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6652519 JAXP issue 48 : Performance Issue with Xalan Transformer
JDK-6652519 : JAXP issue 48 : Performance Issue with Xalan Transformer

Details
Type:
Bug
Submit Date:
2008-01-18
Status:
Closed
Updated Date:
2012-04-24
Project Name:
JDK
Resolved Date:
2008-02-27
Component:
xml
OS:
generic
Sub-Component:
javax.xml.transform
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
saaj1.2,6
Fixed Versions:
1.4.0 (1.4)

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:
Relates:

Sub Tasks

Description
It has been observed that when using the Transfomer to convert a StreamSource to
DOMResult, the performance of Transform gets worse as the size of the
inputstream increases.

How to Reproduce :

The issue manifests in the form of Poor performance of SAAJ for Large Payloads.
SAAJ RI depends on the Transformer.

 import javax.xml.soap.*;

       long start = System.currentTimeMillis();
       MessageFactory mf =
MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
       MimeHeaders hdrs = new MimeHeaders();
       hdrs.addHeader("Content-Type", "application/soap+xml");
       SOAPMessage sm = mf.createMessage(hdrs, new FileInputStream(new
File("msgAttach.xml")));
       SOAPBody body = sm.getSOAPBody();
       long end = System.currentTimeMillis();
       System.out.println("Total Time Taken=" + (end - start)/1000);

Here msgAttach.xml is basically a SOAP Envelope with a large SOAPBody

------------
Profiling has shown that 99.5% of the time is being spent on in
CharacterDataImpl.appendData()

com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.characters(char[], int,
int)  is calling
com.sun.org.apache.xerces.internal.dom.CharacterDataImpl.appendData(String)  and
99.5% of time is spent here.

                                    

Comments
EVALUATION

As shown in the profiling analysis, SAX2DOM makes calls on CharacterDataImpl.appendData(String) to accumulate text. This is very inefficient since a node is created as a string, every call to appendData results in a string concatenation. The fix is to use a StringBuffer to accumulate text before the node is created using the resulting string.

Simple test on a workstation (Sun Ultra 20) shows a transformation of the provided xml file (436kb) from StreamSource to DOMResult which took over 13 min. before now takes only 172ms after the change.
                                     
2008-01-18
EVALUATION

The customer has confirmed that the patch fixed the performance problem they had. This patch has also provided a performance improvement for xml transformation. The fix in jaxp 1.4 will also be integrated into future jdk5/6 update releases.
                                     
2008-02-27



Hardware and Software, Engineered to Work Together