What is the least memory intensive way to apply a stylesheet to an xml document?

bolka

New Member
Consider that I have an XML Document loaded as a byte[] that is 5MB in size. Being a byte array, it takes up exactly 5MB of memory. I have a stylesheet \[code\]Source\[/code\] that I want to apply to this document and perform something like the below. \[code\]final TransformerFactory transformerFactory = TransformerFactory.newInstance();final Transformer transformer = transformerFactory.newTransformer(styleSheet);transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");final StringWriter writer = new StringWriter();transformer.transform(convertStringToSource(filePayload), new StreamResult(writer));return writer.getBuffer().toString().getBytes();\[/code\]When run on the server (WebSphere App Server 7 - with limits on contiguous memory allocation) I get heap dumps that indicate objects of 10 - 15 MB are created. I presume the transform() method will create an object internally, store the original xml as an object, the stylesheet as an object, and the result as an object. Add those together and I'm at a minimum of \[code\]2*input+stylesheet\[/code\] MB. Is there a more efficient way to do this, that keeps my footprint to a minimum?You might say - it's only 10MB, but in my case, performance is critical. The time it takes to allocate that much contiguous memory adds up when I have to transform hundreds or thousands of documents at a time. Thus our server admins have this limit set as a warning of sorts that more memory is being allocated than recommended.FYI, the following JVM parameter sets this in WebSphere: \[code\]-Xdump:stack:events=allocation,filter=#5m?\[/code\].
 
Back
Top