Hi,

(This seems to be JDK issue, but I would like to pinpoint it together with Apache FOP/xmlgraphics developers, since it has significant impact on performance.)

I'm using Apache FOP 1.0 to generate a large number of PDF documents (each having 8 A4 pages). Those documents contain PNG images. One particular image is sized 2035x1875 pixels. This image uses "sRGB IEC61966-2.1" color profile. FOP generates PDF in about 2 seconds.

But, when I switched from JDK 1.6.0_17 to JDK 1.6.0_18 (or latest JDK 1.6.0_24), I noticed that PDF generation takes around 40 seconds. Slowdown is noticable on both CentOS Linux 5.5, and Windows XP. If I remove color profile from PNG, the performance is back to normal ~2s.

Profiler reveals that single method call


org.apache.xmlgraphics.ps.ImageEncodingHelper.encodeRenderedImageAsRGB(RenderedImage image, OutputStream out)

takes ~2s when using 1.6.0_17, and ~40s when using JDK 1.6.0_18. This method in turn calls several transformations for every pixel (~2M times):

    for (int y = 0; y < h; y++) {
        int idx = -1;
        for (int x = 0; x < w; x++) {
int rgb = colorModel.getRGB(raster.getDataElements(x, y, data)); // (*)
            buf[++idx] = (byte)(rgb >> 16);
            buf[++idx] = (byte)(rgb >> 8);
            buf[++idx] = (byte)(rgb);
        }
        out.write(buf);
    }

Now, it seems that marked line (*) calls JDK methods responsible for this slowdown.

I'm stuck here. I'm having hard time profiling JDK methods. I tried to make several thread dumps during execution, and it is always the same native method being executed:

java.lang.Thread.State: RUNNABLE
  at sun.awt.color.CMM.cmmColorConvert(Native Method)
  at sun.awt.color.ICC_Transform.colorConvert(ICC_Transform.java:862)
  - locked <0x2983f388> (a sun.awt.color.ICC_Transform)
  at java.awt.color.ICC_ColorSpace.toRGB(ICC_ColorSpace.java:160)
  (...)

Ironically, in JDK 1.6.0_18 release notes [1], the only issue related to PNG is: "Faster processing of PNG images. (Refer to 6549882.)", which is, again, hidden bug for security reasons.

Having said all this, my proposal is:

1. if someone can help me to track bug further (remember, 1.6.0_17 was working just fine) we could file the bug report to Oracle, or 2. we could just add the info in FOP/xmlgraphics docs that color profile in PNG images introduces significant slowdown on JDK 1.6.0_18+.

What do you think?


[1] http://www.oracle.com/technetwork/java/javase/6u18-142093.html

Reply via email to