danfickle/openhtmltopdf

CSS border-radius makes pdf rendering very slow

mndzielski opened this issue · 2 comments

Hi, I discover that using border-radius with background-image makes that pdf is rendering much longer.

CSS code here:
div.avatar { margin-left: auto; margin-right: auto; height: 200px; width: 160px; background-size: cover; background-position: center center; background-repeat: no-repeat; border-radius: 4px; background-image: url(' base64 here ...') }

HTML:
<div class="avatar"></div>

With border-radius property process takes ~8000ms,
without <70ms. Is there any solution to provide better performance?

Hi @mndzielski,

Although, in my testing the difference wasn't as great as yours, I confirmed the problem and found the culprit. It turns out the AWT Area constructor when passed a shape with curves is very slow (taking over 16 seconds of 22 seconds total in my test and eating up memory). In theory a fix should be easy as the fast mode renderer does not actually need the Area, just the underlying Shape.

However, the Area also seems to be slightly different to its passed in Shape, which means discarding the Area means breaking a lot of tests.

In conclusion, I'll have to experiment more with the Area class, seeing how it changes a Shape before applying a fix.

In the meantime, you may wish to up the memory used by the JVM, as the greater difference between my test and yours may be garbage collection pressure as Area uses a lot of memory (up to 200MB more in my simple test between border-radius and no border-radius).

Ok @mndzielski,

I have applied a quick fix by no longer creating an Area when there is border radius involved. This is not ideal but didn't break any tests (because we had no tests with border radius!) and fixes the speed issue.

As always, thanks for reporting!