JasperReports fillReport too slow and resource consuming JasperReports fillReport too slow and resource consuming xml xml

JasperReports fillReport too slow and resource consuming


The Problem

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.

The Solution

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");

EDIT: That line was deprecated, I've found the correct way to set properties:

DefaultJasperReportsContext context = DefaultJasperReportsContext.getInstance();JRPropertiesUtil.getInstance(context).setProperty("net.sf.jasperreports.xpath.executer.factory",    "net.sf.jasperreports.engine.util.xml.JaxenXPathExecuterFactory");

You will also need to add the Jaxen .jar to your build path. Here is a link: https://mvnrepository.com/artifact/jaxen/jaxen


While the report filling was taking 3-5 minutes with Xalan, it now completes in just a few seconds with Jaxen.

The answer was found here: http://community.jaspersoft.com/questions/536842/jasperreports-too-slow
And also here: http://community.jaspersoft.com/wiki/xml-data-source-very-slow-parse


I was also having this problem when I was exporting pdf, but in my case it seemed to be an infinite loop, because the CPU was hitting 100% when I was trying to generate the JasperReport.

After a lot of research I found this link:

http://community.jaspersoft.com/questions/527078/infinite-loop-subreport-fill

Which my problem was resolved setting my subreports isPrintWhenDetailOverflows="false".