Re: Slow QR Generation

461 views
Skip to first unread message

Sean Owen

unread,
Apr 4, 2013, 6:51:46 PM4/4/13
to zx...@googlegroups.com
I don't know, why do you think this piece is the slow part?

Alonso Vergel

unread,
Apr 4, 2013, 6:57:50 PM4/4/13
to zx...@googlegroups.com
Thank you for your fast answer Owen.

the problem im facing is,  the report without the QR codes (im using 4 of them for each page) takes almost half the time generating than when it have them and thats a really big problem if it have alot of pages.

El jueves, 4 de abril de 2013 17:49:37 UTC-5, Alonso Vergel escribió:
Hi.

Im have some reports developed with ireports and I needed to include QR codes into them. I used zxing and it did the trick
but it turns out now the report is generating really slow.

I used an image object with this in the "image expressio" property :

        com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(new com.google.zxing.qrcode.QRCodeWriter().encode($P{codeBar}, com.google.zxing.BarcodeFormat.QR_CODE, 600, 600))

       ( $P{codeBar} is the string i want to use for the QR )

And java.awt.Image in "Expression Class" property.


I dont know if this is the best way to do it or if i did something wrong... but the report is generating realy slow.

I need some help here, i need to fix that and have a better performance.

If some one can answer, i would appreciate it.

Thank you  =)

Lachezar Dobrev

unread,
Apr 5, 2013, 4:50:21 AM4/5/13
to Alonso Vergel, zx...@googlegroups.com
Hmmm...
I've been dealing with similar needs for the past few days. I hadn't
noticed any slowness, but then again the reports we're generating are
slow to start with (couple of seconds to generate). So I did some
testing: encoding a 200 long string took on my laptop (first set is
different due to OS-level caching):
First set:
First run: 327ms
Next 100: 307ms TOTAL!

Next sets:
First run: 70-90ms
Next 100: 300-320ms TOTAL!

This is the encoding and conversion to a BufferedImage.

When encoding to PNG using ImageIO I get:
First set:
First run: 480ms
Next 100: 370ms

Next sets:
First run: 110-130ms
Next 100: 440-470ms

This is to say, that if there is any slowness it's possible it's
somewhere else, and not the actual QR code generation.

Now I do use Jasper Reports in a J2EE environment, and might have
differences, but I dug deeper and found, that Jasper encodes the image
into a JPeg/PNG (depending on whether the image has alpha channel).
The Matrix-To-Image-Writer generates an opaque image, that I suppose
gets compressed into a JPeg.
It's also possible, that there is some weirdness with the class-loading.

You should try to replace the QR code generation expression with a
plug and see if its similarly slower:
<imageExpression class="java.io.InputStream"><![CDATA[ new
java.awt.image.BufferedImage(600, 600, 1) ]]></imageExpression>

2013/4/5 Alonso Vergel <ave...@dps.com.co>:

Lachezar Dobrev

unread,
Apr 5, 2013, 5:02:52 AM4/5/13
to Alonso Vergel, zx...@googlegroups.com
OK.
I just noted something weird!

When I generate my QR codes I generate them in 1x1 rectangle, that
the encoder enlarges to the needed size.
When I generate the QR codes in a 600x600 BitMatrix I end up having
10-fold increase in time.

QR codes are generally very well scaled up, but the issue with
Jasper Reports is that it encodes the image with a JPeg compression,
that seriously harms unscaled QR Codes.

You could try to generate 1x1 QR codes as me, and tickle the
MatrixToImageWriter to generate an INT_ARGB instead of INT_RGB to
force Jasper Reports to encode it as PNG (due to the alpha channel).
Also remember to use the 'scaleImage="RetainShape"' attribute on the
image.

Alonso Vergel

unread,
Apr 5, 2013, 9:21:38 AM4/5/13
to zx...@googlegroups.com
Thank you for your answer Lachezar Dobrev

i'll try that and see what happens.
Reply all
Reply to author
Forward
0 new messages