JDK-6652519 : JAXP issue 48 : Performance Issue with Xalan Transformer
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.transform
  • Affected Version: saaj1.2,6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2008-01-18
  • Updated: 2013-11-01
  • Resolved: 2008-02-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other Other JDK 6 JDK 7
1.4.0 1.4Fixed 5.0u22-revFixed 5.0u23Fixed 6u14Fixed 7Fixed
Related Reports
Relates :  
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 =
       MimeHeaders hdrs = new MimeHeaders();
       hdrs.addHeader("Content-Type", "application/soap+xml");
       SOAPMessage sm = mf.createMessage(hdrs, new FileInputStream(new
       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

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.

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.

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.