Gert Van der Voorde created FREEMARKER-207:
----------------------------------------------

             Summary: Slow processing of large xml files freemarker
                 Key: FREEMARKER-207
                 URL: https://issues.apache.org/jira/browse/FREEMARKER-207
             Project: Apache Freemarker
          Issue Type: Bug
          Components: engine
    Affects Versions: 2.3.29, 2.3.31
            Reporter: Gert Van der Voorde


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.
{code:java}
 @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;
    } {code}
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



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to