Optimizing lots of meshes with limitations

Babylon Version: 7.54 | WebGL Engine

I am trying to give my scene a performance boost and am looking for any suggestions on how. I have an application that displays data sets of models. The problem is the number of meshes in the models can get quite large.

In the worst case I am seeing about 6000 meshes, with ~96000 active faces and ~3000 draw calls.

I can’t use instancing because each mesh has the capability of being unique, and I can’t merge meshes because I need to be able to select and highlight each mesh individually.

For a lot of angles the meshes are almost all active in the scene, and using occlusion queries seems to result in worse performance than without.

With most systems I test this on the FPS sits around 10-20 on my worst case scenarios.

Looking at the chrome performance profiler, the majority of time is spent in RenderSorted with the bind calls.

(My active meshes is weirdly only displaying the meshes in a viewport camera)

Has anyone optimized a situation like this to be more performant? Or have any general solutions to look into that may boost performance when dealing with a ton of meshes than cant be instanced or merged?

Any ideas are appreciated, and I’ll do my best to answer any questions I can about my scene setup

One angle could be to reduce the overload of selecting active meshes. At least worth a try:

Optimizing Your Scene | Babylon.js Documentation

in a nutshell:

  • Make sure to have all meshes always active with :mesh.alwaysSelectAsActiveMesh
  • Freeze the list: scene.freezeActiveMeshes();

You may also want to try this:
Optimizing Your Scene | Babylon.js Documentation

Discovered that the number of model faces contains decimal points

That’s just a heuristic (activeFaces = activeIndices / 3)

But I feel that this algorithm is incorrect, it needs to traverse each mesh to be accurate

The scene can get pretty dynamic with lots of assets loading an unloading as the camera moves (using asset containers to speed up the process so I can do it without disposing), or gltf files being loaded on delays over a network download.

I make use of all the other suggestions in the Scenes with Lots of Meshes section already.

I don’t think the active mesh evaluation is that time consuming based on the profile (2ms of the ~90ms render time) but do you think its more or less performant to unfreeze the active meshes when adding/removing and then refreeze or to just leave it dynamic.

Well it is worth testing :wink: