TIBCOSoftware / jasperreports

JasperReports® - Free Java Reporting Library
https://community.jaspersoft.com/downloads/community-edition/
GNU Lesser General Public License v3.0
1.04k stars 401 forks source link

Very slow reports filling with styled text fields #236

Closed kuseman closed 2 years ago

kuseman commented 2 years ago

Hi, we have reports that make use of styled text fields and the report filling is really slow. We have an external styles file included

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperTemplate PUBLIC "-//JasperReports//DTD Template//EN" "http://jasperreports.sourceforge.net/dtds/jaspertemplate.dtd">

<jasperTemplate>
    <style name="header1-key" forecolor="#1A96C2" fontName="DejaVu Sans" fontSize="10"  pdfEncoding="Identity-H" isPdfEmbedded="true"/>
    <style name="header1-value" forecolor="#000000" fontName="DejaVu Sans" fontSize="10"  pdfEncoding="Identity-H" isPdfEmbedded="true"/>
    <style name="header2-key" forecolor="#1A96C2" fontName="DejaVu Sans" fontSize="8"  pdfEncoding="Identity-H" isPdfEmbedded="true"/>
    <style name="header2-value" forecolor="#000000" fontName="DejaVu Sans" fontSize="8"  pdfEncoding="Identity-H" isPdfEmbedded="true"/>
    <style name="regular" forecolor="#000000" fontName="DejaVu Sans" fontSize="8"  pdfEncoding="Identity-H" isPdfEmbedded="true"/>
    <style name="footer" forecolor="#000000" fontName="DejaVu Sans" fontSize="8"  pdfEncoding="Identity-H" isPdfEmbedded="true"/>
    <style name="row-base" mode="Transparent" vAlign="Middle" fontName="DejaVu Sans" fontSize="8" pdfEncoding="Identity-H" isPdfEmbedded="true" />
</jasperTemplate>

And text fields like this

<textField>
    <reportElement style="footer" x="15" y="788" width="200" height="12" uuid="8a87862a-09ca-43af-b08f-e9408daac9ce"/>
    <textFieldExpression>some value</textFieldExpression>
</textField>

I've load tested one of our reports and recorded the process with JFR and the problem seems to boil down to really ineffective XML-parsing starting at https://github.com/TIBCOSoftware/jasperreports/blob/master/jasperreports/src/net/sf/jasperreports/engine/util/JRStyledTextParser.java#L250

Recording of allocations below is from a 2 minute test of generating the same report over and over again with an avg. of 5 second per generation. The SQL backing data source returns 1800 rows pretty much instant.

image

That's insane amount of allocations.

Is there anything we are doing wrong in our reports, can this be optimized?

Jasper: 6.18.1 JVM: OpenJDK 64-Bit Server VM (11.0.10+9-LTS, mixed mode) Java: version 11.0.10, vendor Azul Systems, Inc.

Fixed in #237

teodord commented 2 years ago

Hi,

The JRStyledTextParser performance does not have anything to do with the use of styles for text elements or with the use of style template files as you described above. It only has to do with the markup property or the now deprecated isStyledText property of a text element. Indeed, these can be declared in styles and inherited from there, but your example does not contain any of them.

But it is true that an optimization can be made to avoid attempting parsing XML if there is no < character in the text element value. In fact, this test can be made at a higher level.

Thank you for your suggestion. Teodor