[ https://issues.apache.org/jira/browse/PDFBOX-2126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14045190#comment-14045190 ]
Petr Slaby commented on PDFBOX-2126: ------------------------------------ Attached updated patch against latest trunk. I have moved the intersection of current clipping path with new clipping into PDGraphicsState#setCurrentClippingPath() to avoid duplicate code on places where this method is called (a second call has been added in PDFBOX-1875 now). There is a performance optimization in the computation of intersection trying to avoid creation of Area wherever possible. I do not insist on that, but it brought a big performance and memory consumption improvement on a corner case PDF where a very complex clipping path is used. It brought also some one pixel differences on a few of my test files, but I am not able to decide whether the "before" or "after" is correct. I am still hesitant to make the clip path immutable and private to the PDGraphicsState as that would mean to make a clone of input in setClipPath() and either a clone of output in getClipPath() or an introduction of methods like applyClipping(Graphics2D) and fillClipPath(Graphics2D) in PDGraphicsState. > Optimize clipping > ----------------- > > Key: PDFBOX-2126 > URL: https://issues.apache.org/jira/browse/PDFBOX-2126 > Project: PDFBox > Issue Type: Improvement > Components: Rendering > Affects Versions: 2.0.0 > Reporter: Petr Slaby > Attachments: ClipPath.1.patch, ClipPath.patch, example_010.pdf > > > As already stated in a TODO comment in PageDrawer, the call of > Graphics2D#setClip() is time and memory consuming. The attached patch > optimizes clipping by calling Graphics2D#setClip() only if the clipping path > has changed. The effect depends on the document, e.g. the attached one > renders in 10.5s without the optimization and in 5.5 seconds in the optimized > version. > The clipping has to be re-applied whenever the transform in Graphics2D > changes. This is not explicitly checked for, the implementation rather > depends on the cached value being reset manually. Currently this is only > needed at one place when processing annotations (AcroForms). Also, the > implementation relies upon the clipping path object stored in PDGraphicsState > to never change so that a comparison using == can be used. This works fine, > but needs a bit of awareness in future changes. To make the design more > clean, the clipping path could be made private to PDGraphcisState and thus > really "immutable" from outside. -- This message was sent by Atlassian JIRA (v6.2#6252)