InstancedMesh for simple geometries?

Using InstancedMesh with a single triangle is very unlikely to improve performance — Mesh is already a collection of triangles, and is the most efficient way to represent that. I don’t think there is any specific number of vertices that would lead you to choose merging vs. instancing in all cases and all devices.

I understand InstancedMeshes to be better than merging geometries…

I’m not aware of any rule of thumb to say this. All WebGL applications have limits in terms of:

  • number of draw calls
  • other CPU bottlenecks
  • CPU memory
  • GPU memory
  • cost of GPU fragment shader, and other GPU bottlenecks
  • cost of initializing the scene and updating for each frame

If you’re bottlenecked by draw calls, merging or using InstancedMesh are both good ways to improve that. If you test this example…

https://threejs.org/examples/?q=performan#webgl_instancing_performance

… I find framerate to be a touch better with merging than instancing on my machine, but I don’t know if that’s universally true. And certainly the memory cost of merging is higher. There’s no one “right” choice to decide between using more CPU time or more memory. You’ll need to optimize and test for the limits you are hitting, and the performance goals of your app; it is a multi-dimensional optimization and not reducible to vertex count.

3 Likes