# Performance optimization can cause meshes disappear

**URL:** <https://forum.babylonjs.com/t/performance-optimization-can-cause-meshes-disappear/45180>\
**Category:** Questions\
**Tags:** performance\
**Created:** [October 25, 2023, 7:39am UTC](https://forum.babylonjs.com/t/performance-optimization-can-cause-meshes-disappear/45180 "2023-10-25T07:39:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Jamin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ben_jamin/32/35419_2.png) [@Ben\_Jamin](https://forum.babylonjs.com/u/Ben_Jamin)\
**Post date:** [October 25, 2023, 7:39am UTC](https://forum.babylonjs.com/t/performance-optimization-can-cause-meshes-disappear/45180/1 "2023-10-25T07:39:56Z")

</div>

Hi everybody,

I am working on a project that can have very large mesh counts (at now for about 2500 but expected to have more in the future). Every mesh may have different shapes and dimensions which means that I cannot use instance. So, I decided to use if there are other solutions for me to optimize the scene.

I am now having at max 2500 drawcalls (since I don’t need always show them all) about 10 materials, 1 light and no textures. I am experiencing about only 20 frames per second.

To make the problem feel clear, I would like to do a brief introduction on my project and how I have done till now to try to fix the problem:

1. It is a simulation project (digital twin) that can connect to real world situations. Because of that, I will have to do a lot of calculation on the position and rotation on the coordinate to make it work in BJS. Currently I found that the TransformNode.lookAt() and TransformNode.rotate() takes a lot of time to compute.  

2. So, I decided to make these functions to be called at a web worker. However, this seems does not to work when I pass anything inside BJS to the webworker(e.g., TransformNode or Vector3). And at here, I notice that the performance issue may not related to the calculation, since it was stuck at the same framerate no matter I do the calculation or not.

3. Then I went to the documentation of optimizing the scene, [(Optimizing Your Scene | Not updating the bounding info)](https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#not-updating-the-bounding-info). By adding `mesh.doNotSyncBoundingInfo = true;` My scene looks really weird like this:  
 ![Honeycam 2023-10-25 09-29-15](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/7/172898d17f1e798425d41a5d99a4f5488b031275.gif)  
What it normally shows is this:  
 ![Honeycam 2023-10-25 09-31-57](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/e/befb65f74d0e7debe337d113cda49adb7382bf62.gif)  
You can see that some of the meshes can be disappeared.

Does anybody have ideas on this?

---

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [October 25, 2023, 7:58am UTC](https://forum.babylonjs.com/t/performance-optimization-can-cause-meshes-disappear/45180/2 "2023-10-25T07:58:57Z")

</div>

The doc says “In conjonction with `mesh.alwaysSelectAsActiveMesh`”, so set `mesh.alwaysSelectAsActiveMesh = true` and see if it works.

---

<div class="post-metadata">

**Author:** ![Ben\_Jamin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ben_jamin/32/35419_2.png) [@Ben\_Jamin](https://forum.babylonjs.com/u/Ben_Jamin)\
**Post date:** [October 25, 2023, 8:07am UTC](https://forum.babylonjs.com/t/performance-optimization-can-cause-meshes-disappear/45180/3 "2023-10-25T08:07:11Z")

</div>

Thanks for the fast reply!

Yes, it seems to be displayed correctly, however, the draw calls stay in 2000, that is what I do not want, since this make the framerate even worser.

Do you have any other ideas on how I can improve the performance?

---

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [October 25, 2023, 8:57am UTC](https://forum.babylonjs.com/t/performance-optimization-can-cause-meshes-disappear/45180/4 "2023-10-25T08:57:09Z")

</div>

[Join](https://gltf-transform.dev/modules/functions/functions/join) meshes with the same material if they are not required to move (TRS or bone animations)  
[Thin Instances](https://doc.babylonjs.com/features/featuresDeepDive/mesh/copies/thinInstances) can also be used if many meshes share the same vertex and material.  
[`EXT_mesh_gpu_instancing`](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/) can be imported as thin instances.

---

<div class="post-metadata">

**Author:** ![Ben\_Jamin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ben_jamin/32/35419_2.png) [@Ben\_Jamin](https://forum.babylonjs.com/u/Ben_Jamin)\
**Post date:** [October 25, 2023, 2:41pm UTC](https://forum.babylonjs.com/t/performance-optimization-can-cause-meshes-disappear/45180/5 "2023-10-25T14:41:50Z")

</div>

Thanks! I know that people can use instance to reduce draw call, but how can I use instance on my situation? In my knowledge, instance can only be used when you have a lot of similar(identical) objects, the only thing you can adjust on the dimension of the mesh is scale. In my case, I have made all of these meshes “manually”, meaning that I generate them using their vertex coordinates, so it is likely that they are different to each other. Are there still other solutions for this case?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 25, 2023, 7:25pm UTC](https://forum.babylonjs.com/t/performance-optimization-can-cause-meshes-disappear/45180/6 "2023-10-25T19:25:09Z")

</div>

Did you try those ? [Optimizing Your Scene | Babylon.js Documentation](https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#performance-priority-modes)

Also mergeMeshes in your case might help a lot I guess.

---

<div class="post-metadata">

**Author:** ![kzhsw](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kzhsw](https://forum.babylonjs.com/u/kzhsw)\
**Post date:** [October 26, 2023, 1:09am UTC](https://forum.babylonjs.com/t/performance-optimization-can-cause-meshes-disappear/45180/7 "2023-10-26T01:09:40Z")

</div>

Assuming the meshes in your scene is static, another way is to [export your scene to gltf](https://doc.babylonjs.com/features/featuresDeepDive/Exporters/glTFExporter) and run things like [dedup](https://gltf-transform.dev/modules/functions/functions/dedup), [flatten](https://gltf-transform.dev/modules/functions/functions/flatten), [instance](https://gltf-transform.dev/modules/functions/functions/instance), [join](https://gltf-transform.dev/modules/functions/functions/join), and [import it](https://doc.babylonjs.com/features/featuresDeepDive/importers/glTF) back.
