19

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.
  • The datasource is a pretty big XML file (about 100k lines, 1.5Mb)
  • The machine is a 3Ghz dual core with 4Gb of RAM

So, how can I improve report filling performance?

Salvatorelab
  • 11,614
  • 6
  • 53
  • 80
  • DO you have the stats of how the performance is after you switched to xalan ? – vsingh Jun 09 '17 at 22:59
  • @vsingh As I said in the answer: "While the report filling was taking 3-5 minutes with Xalan, it now completes in just a few seconds with Jaxen" – Salvatorelab Jun 12 '17 at 09:40
  • Are you using virtualizer ? We are facing challenges to generate large reports. In this case we pass in the complete data set https://stackoverflow.com/questions/44467407/large-report-generation-with-jasper-using-virtualizer-takes-too-much-time – vsingh Jun 12 '17 at 14:25

2 Answers2

24

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

Salvatorelab
  • 11,614
  • 6
  • 53
  • 80
  • 1
    jasper report version 6.3.1 is much faster than Jaxen – Vinayak Dornala Dec 29 '16 at 15:46
  • 1
    As of 6.4.1, changing to jaxen results in a 5:1 reduction in XML processing time for content size in the vicinity of 1MB. So yeah, still an awesome solution, thanks a bunch. – TheGerm Aug 31 '17 at 18:49
  • What will be the alternative to this solution if the datasource is not XML but a JRDataSource set as a parameter in the report? – Jaideep Sagar Oct 26 '22 at 06:54
4

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".

jairobjunior
  • 473
  • 5
  • 11