# [OpenJDK 2D-Dev] sun.java2D.pisces big memory usage & Dasher clipping problem

Jim Graham james.graham at oracle.com
Mon Apr 1 10:36:28 UTC 2013

```
On 3/30/2013 5:25 AM, Laurent Bourgès wrote:
> I would like first try / do simple things: skip segments totally out of the clipping + margin (10%) to avoid the dasher create millions of invisible segments.
> it seams simple but check each segment could become a performance bottleneck too !

Two caveats:

- For curves, just compare the control points, not the tight curve to save time.  Bezier curves are guaranteed to live inside the convex hull of their control points.

- For miter joins, you have to adjust that 10%, or whatever margin you use based on the miter limit.  I'm assuming you meant "margin = line width + 10%", but it should be "margin = line width * miter limit + 10%", unless the join style is not "MITER" in which case you can treat the miter limit as 1.0.

> For complex shapes (curves), it could be interesting to take into account the spatial resolution: for example a curve that represents less than 1 (AA) pixel should be skipped ... it can apply to caps (mitter, bevel, rounded) too!

For skipping in the renderer maybe, but if you try to apply that logic in the pre-stroking stage then keep in mind that a very tiny curve could sweep a very large angle and cause a very large number of pixels to be rendered.  In the simplest case stroking a zero length line segment with square caps will minimally draw a rectangle that is lw x lw.  Think of a tiny person holding a very long pole across their chest.  As they move the pole sweeps out the line's area.  They may spin in place, and you might think to ignore that move, but that pole is going to be sweeping out a huge area around them.

> Do you look at the java2D Pisces code, Jim ?
> I think it quite difficult to understand (only few comments / explanations ...). Does somebody know if there is some docs on this implementation / algorithms ?

I have worked extensively with it.  Denis Lila did the major work to create what it is today, but I was doing the code reviews every step of the way.

We've also integrated a version of it into JavaFX and ported it to native code as part of that project.

...jim

```