I've found that JasperReports is really slow when filling a report from a Java app. The program hangs at this line:
print = JasperFillManager.fillReport(report, parameters, xmlDataSource);
It usually stays there for 3 minutes, consuming up to 300Mb of RAM and 50% CPU.
report
is a compiled (.jasper) report that uses 3 subreports.So, how can I improve report filling performance?
It seems that the problem is the XPath engine. That is, the library that parses the XML file looking for data.
While iReport Designer uses Jaxen, JasperReport uses Xalan. Xalan is really slow compared to Jaxen (really really slow).
That's why the problem only occurs when filling the report from a Java application and not from iReports.
Well, the solution is simple, just add the following line in your Java application to select Jaxen lib instead of the default Xalan lib (it's deprecated, but it works):
JRProperties.setProperty("net.sf.jasperreports.xpath.executer.factory",
"net.sf.jasperreports.engine.util.xml.JaxenXPathExecuterFactory");