Update: JPDF2HTM5 has been rebranded as BuildVu and JPDFForms has been rebranded as FormVu

Annoying Java Bugs – Java Shape code performance

I have been looking at a customer PDF file which seems to ‘hang’ on a page. It actually shows up the limitations of Java Shape code performance.

The page in question contains a couple of very high resolution Vector graphics – the command stream is 252 million characters long! Seems a bit excessive but it opens quickly in Acrobat. Most of the stream commands consist of clipping commands and shapes to draw the shading on a picture of a giraffe – it does look really cool if you zoom in to 6400% in Acrobat! We handle shapes and clipping in Java using the Shape and Area classes.

When we profiled the page, we found that the page contained 9000 complex clips and that the ‘hanging’ was actually the time executing the Shape code. In particular the Area methods equals() and intersect() are VERY slow on  complex shapes. The performance hit is down to the complexity of the shapes not the number of shapes.

So the fix is to use the outline of the Shapes, not the shapes themselves if they are too complex. It is a compromise and it would be nice to see Oracle improve the performance of these classes…

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

2 thoughts on “Annoying Java Bugs – Java Shape code performance

  1. That’s actually not something that is unique to the Java environment: I’ve seen similar things with Adobe interpreters. One extreme example was a simple web page that when converted to PDF took about 30 minutes to print. The problem was a combination of transparency with shading patterns.

    As long as we have to deal with limited computing resources, there will always be files that take forever to process.

  2. Nasty 🙁

    You also find a little trick you used to optimise one case degrades another due to the sheer number of ways people use the PDF file spec.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>