Scene optimization questions

Hi, I followed all the steps from scene optimization and somehow I ended with a lower fps than before :frowning: I don’t know what I’m doing wrong.

I can’t share it with you, but I’ll try to give you a little context.
It is a huge scene completly loaded as gltf, only with static meshes, and most of them are instancedMeshes(trees, bushes, buildings). As player you can move through it using a firstPersonCamera which is an UniversalCamera from babylon. You can move using keyboard keys or on click on the ground. This is it.
Before to apply the optimizations, it had a fps range between 55 and 70 and the drawcalls, actived meshes and absolute fps varied a lot.
After optimizations the scene looks more stable, the fps vary less, like between 55 and 65 aprox, and only fps and absolute fps are changing, but their values are a litle bit smaller than before

What I did for optimization

* mesh.freezeWorldMatrix();
    if (mesh.material) {
      mesh.material.freeze();
      mesh.isPickable = false;
      mesh.enablePointerMoveEvents = false;
      mesh.doNotSyncBoundingInfo = true;
    }

* this.engine = new Engine(  canvasContainer,  true, { preserveDrawingBuffer: true,  stencil: true,  },  false );
    this.engine.renderEvenInBackground = false;
    this.engine.enableOfflineSupport = false;
    this.engine.disableManifestCheck = true;
    this.engine.disablePerformanceMonitorInBackground = true;
    this.engine.doNotHandleContextLost = true;

* this.scene.skipFrustumClipping = true;
    this.scene.preventDefaultOnPointerDown = false;
    this.scene.preventDefaultOnPointerUp = false;
    // this.scene.autoClear = false; // I can't because is open scene
    // this.scene.autoClearDepthAndStencil = false; // I can't because is open scene
    this.scene.clearColor = new Color4(0, 0, 0, 0);
    // this.scene.skipPointerMovePicking = true;  // I can't because there is a circle which follow the mouse cursor
    this.scene.setRenderingOrder(0,  null,  null,  RenderingGroup.PainterSortCompare );

A performance tab capture

Is there something which I can do more? Or did I do something wrong?

I’m using babylonjs v5.54.0, if you need more info, please let me know
Thanks

Your active mesh count and draw calls went up after your optimizations. Are you sure these comparisons are using the same camera frustum?

Yes, exactly the same scene and camera.
I think it is somehow expected because with optmization everything is freezed and the bounding Info is not refreshed so the camera take all the meshes from scene, because of this drawcalls and activeMeshes not change while moving, …maybe I’m wrong

later edit: actually there are 2 meshes and 2 materials more with optimizatitons, I’ll check from where they come. But I don’t think they have such a big influence

There are 136 more draw calls on the first scene so that definitely makes a big difference.

Since you said most of the meshes are static, you could freeze the world matrix of those. You can also try the performance priority modes instead of trying to change individual features: Optimizing Your Scene | Babylon.js Documentation

I already did this, freezeworldMatrix() foreach object, freeze material, disable picking and not sync bounding Info

There are 136 more draw calls on the first scene so that definitely makes a big difference.

They are all the meshes from scene
Not doNotSyncBoundingInfo is the responsale for this?

It should not if your meshes are static and only your camera is moving.

1 Like

Try setting this.scene.skipFrustumClipping to false instead of true to have more meshes removed from processing early.

2 Likes

Hi, yes, this was the reason of so many draw calls. It was a missunderstanding from my side :frowning:
If I set this to false it is working as expected, and “my fps” are back :raised_hands: :raised_hands: :raised_hands:
Thanks!

Do you have any suggestions besides the above I already tried?

Have you seen this page:

There is a lot of information there (and also in this forum).

1 Like

Hi, yes, most of the optimizations I did were from there