Using PolygonMesh? Read this to ensure best performance

As of SketchUp 2021.1 the Geom::PolygonMesh class has gotten a speed boost for large meshes.

Using polygonmesh with entities.fill_from_mesh has been the fastest way to add bulk geometry via the Ruby API. However a major bottleneck was in how it de-duplicated the points/vertices for the mesh. This lead to a O(N^2) performance which scales really poorly as the number of points increases.

We made improvements that now makes this O(logN), however, there are pre-requisites to experiencing the improvement.

The new algorithm is only faster for larger meshes. For smaller meshes the existing implementation was faster. So there is a switch logic that picks which approach to use. This means that you need to provide the number of points to the constructor of the mesh for it to be able to know when to switch. If you leave this out then it’ll always use the old logic of de-duplicating the points.

Ideally you provide an accurate count of number of points the mesh will consist of. If that’s a challenge to know up front, then make an estimate an favor overestimating rather than underestimating.

Looking at Geom::PolygonMesh usage on extensions on Extension Warehouse we saw about a 50%/50% split between extensions providing or not providing a count of points to the constructor.

If you create bulk geometry using Geom::PolygonMesh please consider reviewing your code and see if you are getting the benefits of the performance improvements in SU2021.1.

Some number from our performance testing:

6 Likes