Performance issue with mesh creation?


Using 4.2.0, I’m noticing that dynamic mesh creation seems to cause noticeable performance drops. I’ve see this when creating SolidParticleSystems, and also when manually creating vertex/index/color/uv data and then calling vertexData.applyToMesh.

I think (but have not specifically checked) that performance used to be noticeably better in early versions.

Here is a playground demoing what I mean. It basically creates an SPS every 10 frames, made out 100 spheres. For me (measuring in chrome using the performance profiler) building such meshes exceeds the frame budget, and also there are occasional spikes where it takes significantly longer than usual (presumably due to GC pressure). Of course in an actual project where other stuff is going on the effect is a lot worse.

Is this unavoidable, or is there an issue here that could be addressed?

Adding @jerome who created the SPS but I’m not sure he could do a lot if just calling the underlying mesh methods…

Maybe you should profile the PG and see where the time is spent to help moving forward. Normally mesh creation is not a bottleneck because it happens infrequently (mostly at start), so I think you would need to provide more insight for people to get interested in this case :wink:

@Evgeni_Popov Sorry, I don’t know what you’re asking for. Naturally I profiled already, the PG is right there in the link. The time is mostly spent in _insertNewParticle > _meshBuilder.

Basically, building an SPS with 100 particles is taking ~40ms (sometimes much longer). Is that expected?

Providing the methods where the time is spent (like _meshBuilder) was what I meant with “you would need to provide more insight”.

This method must extract the data (positions, uvs, normals, …) from your mesh to add it to the SPS, so it can take some time, all the more if your mesh has a lot of faces. In your PG, each sphere has 1296 faces, so you add 1296*100=129600 faces each time you make a SPS. Also, those data must be uploaded to the GPU after creation.

If you lower the number of faces of the sphere, you can improve the performance quite a bit.

I don’t know if the method can be improved, here it is if you want to have a look: