Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.3.29, 2.3.31
-
Patch
Description
I had a problem when using Freemarker with xml 's containing large content ( > 600KB)
The problem is in the class ElementModel in method getAsTring in package freemarker.ext.dom.
The number of nodes were high, more then 10 000 and when using String concatenation as in the following snippet the performance was/is very poor.
@Override public String getAsString() throws TemplateModelException { NodeList nl = node.getChildNodes(); String result = ""; for (int i = 0; i < nl.getLength(); i++) { Node child = nl.item(i); int nodeType = child.getNodeType(); if (nodeType == Node.ELEMENT_NODE) { String msg = "Only elements with no child elements can be processed as text." + "\nThis element with name \"" + node.getNodeName() + "\" has a child element named: " + child.getNodeName(); throw new TemplateModelException(msg); } else if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { result += child.getNodeValue(); } } return result; }
For a xml file of 600kb this took 6 to 11 seconds to process.
When using a StringBuilder this takes 60 ms.
I already made a pull request for this : https://github.com/apache/freemarker/pull/82