Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Clipping Polygon Performance #12258

Open
ggetz opened this issue Oct 18, 2024 · 2 comments
Open

Improve Clipping Polygon Performance #12258

ggetz opened this issue Oct 18, 2024 · 2 comments

Comments

@ggetz
Copy link
Contributor

ggetz commented Oct 18, 2024

Feature

#11750 added an initial implementation of clipping polygons. However, some users are seeing performance hits depending on usage.

The performance hit is not directly correlated with the number of polygon positions. The geographic extent, concavity, and number of polygons also factor in. For example, the AEC Clipping Example is a particularly concave polygon with many positions shows this performance hit.

@ggetz
Copy link
Contributor Author

ggetz commented Oct 18, 2024

Also reported in #11750 (comment)

@javagl
Copy link
Contributor

javagl commented Oct 19, 2024

The performance hit is not directly correlated with the number of polygon positions.

Certain aspects of the polygon shape may have an additional impact here. (For example, a polygon with 100 points that covers a pole and the IDL may have a larger impact than one that does not). But the performance hit is definitely correlated with the number of polygon points.

I created a sandcastle where you can crank up the number of polygon points from 4 to 500 (and it's a circle - i.e. as convex as it can be). And one can clearly see the performance hit:

Cesium Clipping Polygon Performance

The sandcastle:

https://sandcastle.cesium.com/index.html#c=hVZbU9s4FP4rmrzUWVwlFNi2ITA7DQvtTrswDdsXwoMiK7EGWfJIcqjb4b/vkeRrMG0eYl3O9dO5USWNRTvOHplGZ0iyR7RghhcZ/ubPotWI+v1CSUu4ZHo1itHPlUTI8owJOJmhDRGGxe6MSJ4Ry5XsHhrKJPuiEnbD6QPT3as1MewzKZl+frUVat2R/TQ+XcmVDJZiLxInbF1sl6l6vNQkY+aG6SWjSibgiNUF8wzUO2i5YIZZuCCPhNvaR6oZsexKqa1gN6myCvaCG8vp0cVtYImc3p7WXPOMW75jBpMkiSrRwbxNIalzHwXJC64pSFZcWhMBs2X6s5IxqpbExkiThBcmRrLIAt04oBvszv0RmH13f+pON0qjSIAjHM6mp/CZt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uIH5oCChjjqnkOZyn21ItA7OmakIloymDETfZ9/ZUEl52BK9geh5BfyVE8mhtbCuYL4l88y5WGENIiwnhiWZYL180n6wJ4IemNj575pGaZJ3yHeHI2MNtDOSDG9cpNIcSS/4Ah43w+Afoem2sWYN/1jmlBSkeSHp5/DoeA0XwC2+dcTbB5q+fWPWZV0ed2rZLyvH7JudXnbb2b2+Q8JBFSm6pFzidw2CfpzjRzLvPC+ukHFGtXesC3jEvYubkrI99hBYUE1sayHDaHsHQt7fUaIh72vgPN2kyOkT8Js8UMvfIaXlXODOu17Lt1CgBGp+03Cnqiev7BpsYDlg1SsK4gDFj/Dw

Looking at a performance trace reveals (some of) the (potential) culprit(s):

Cesium Clipping Polygon Performance 0001

Apparently, computing that rectangle for the clipping polygon takes a lot of time.

There are a few places where one could consider performance improvements. Computing this rectangle in each and every frame is certainly wasteful: I think that the positions of such a polygon will rarely change dynamically. But it is really important to be able to change them dynamically: We want the possibility to interactively drag around the points and update the clipping (...to eventually hit "Confirm" somewhere, and write some clipped result into a file or so...).

As an experiment, I just created a (hacky!!!) branch that just caches this rectangle, based on the positions.

(Yeah, storing the positions twice is also wasteful, in terms of memory - that's the usual trade-off. There are no fine-grained access controls (as in "information hiding") that would allow detecting modifications of the positions. Throwing in some function like clippingPolygon.updateThatStuff() that the user has to call after updating the positions wouldn't be ideal either. This is just an experiment, and clearly marked as such...)

The main point of this experiment is shown at the end of the GIF above: When using the check box to set that ClippingPolygon.hackyCaching flag (that is used in that branch to enable the caching), the FPS goes back to 60.

Maybe there's a "good" way to avoid recomputing that rectangle in each frame...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants