jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.58k stars 505 forks source link

Performance improvements for retessellate #1250

Closed achirita closed 1 year ago

achirita commented 1 year ago

All Submissions:

Based on this discussion https://github.com/jscad/OpenJSCAD.org/discussions/1247 I have refactored retessellate.js to improve performance. This function is used by all boolean operations and is the main reason why sometimes they're really slow. To measure the performance I used a geometry with ~15k polygons which gets reduced to ~7.5k polygons. Results for current implementation of retessellate.js :

Results for new implementation:

There is an ~5x overall performance improvement, but if we exclude the calls to reTesselateCoplanarPolygons there's more like an ~25x improvement.

I haven't added this test to the existing suite because I didn't want it slowing down build times. If you consider it should be added, I can work something out.

z3dev commented 1 year ago

@platypii wouldn't this be more appropriate in V3?

platypii commented 1 year ago

wouldn't this be more appropriate in V3?

Based on the tests being unchanged, it seems like @achirita implemented this in a way which does not change the output result at all. So it is not a breaking API change.

I think anything without breaking changes should go in V2 still. Why? Because V3 is not ready yet, who knows when it will be ready. But users are actively using V2, so improvements are nice, and usage also let's us find and fix bugs sooner.

z3dev commented 1 year ago

@platypii can you follow with lint changes for V2 modeling?