# Determining NullEngine fps

**URL:** <https://forum.babylonjs.com/t/determining-nullengine-fps/25516>\
**Category:** Questions\
**Tags:** performance, nullengine, optimization\
**Created:** [November 23, 2021, 10:17pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516 "2021-11-23T22:17:37Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Panuchka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/panuchka/32/12054_2.png) [@Panuchka](https://forum.babylonjs.com/u/Panuchka)\
**Post date:** [November 23, 2021, 10:17pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/1 "2021-11-23T22:17:37Z")

</div>

Hi everyone!

Just a quick question about the best way to determine NullEngine fps. I just would like to assure that the engine runs in a stable fps all the time… Not sure if the best way is to console log the `engine.getFps().toFixed()` what I tried to do just a few minutes ago 😅 … Any tips for this?

Also a continuation why I’m asking; getting a fluctuating NullEngine fps of ~40, even though it is _supposed_ to run at 60 fps…

---

<div class="post-metadata">

**Author:** ![Panuchka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/panuchka/32/12054_2.png) [@Panuchka](https://forum.babylonjs.com/u/Panuchka)\
**Post date:** [November 23, 2021, 10:39pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/2 "2021-11-23T22:39:25Z")

</div>

Answering a bit to the question; `node --inspect` works wonders on creating a node process where you can hook your regular Chrome debug tools:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/d/5da05bb8e52837fe3fbdb3b7dc26ad76775089d5.png)  
There is still the problem of “how to see the NullEngine fps reliably part” 😃 Also curious on how the camera processing works in the NullEngine…

---

<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:** [November 23, 2021, 11:08pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/3 "2021-11-23T23:08:11Z")

</div>

getFps is the way to do it and in nullengine everything but gpu operations are executed.

It might be your RAF equivalent not being fast enough ? cause it looks like your full frame runs in about 3ms

---

<div class="post-metadata">

**Author:** ![Panuchka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/panuchka/32/12054_2.png) [@Panuchka](https://forum.babylonjs.com/u/Panuchka)\
**Post date:** [November 23, 2021, 11:19pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/4 "2021-11-23T23:19:19Z")

</div>

Hmmm, it is a bit hard pickle. I do have a lot of instanced meshes in the scene, but somehow I thought that not actually rendering would not eat my performance so much… 😃 Here is even bigger picture:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/2/f/2f0dfc068bfc2ad05b56347289ed8f7177e39389.png)

Can you provide any insight in what could be done, other than reduce mesh amount… 😅

---

<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:** [November 23, 2021, 11:34pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/5 "2021-11-23T23:34:33Z")

</div>

at least in node you could freezeActiveMeshes() on the scene to bypass your biggest cost. Babylon is actually CPU bound so I am not surprised your frames are pretty similar.

---

<div class="post-metadata">

**Author:** ![Panuchka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/panuchka/32/12054_2.png) [@Panuchka](https://forum.babylonjs.com/u/Panuchka)\
**Post date:** [November 23, 2021, 11:45pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/6 "2021-11-23T23:45:04Z")

</div>

Nice, that did the trick with the meshes problem! Fps is around ~53 now!

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/c/4c288315dfeef8a420ab7a39dd02a2aaac07c311.png)

Now the bottleneck seems to be the Recast blackbox. I guess the animation section might be in relation with this as well, as I should have disabled all the animations in the server side 🤔 I’m kind of curious how much power the crowd calculation is taking since there is just one agent standing, not doing anything 😃

---

<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:** [November 23, 2021, 11:56pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/7 "2021-11-23T23:56:34Z")

</div>

Let s check this one with @Cedric

---

<div class="post-metadata">

**Author:** ![Panuchka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/panuchka/32/12054_2.png) [@Panuchka](https://forum.babylonjs.com/u/Panuchka)\
**Post date:** [November 24, 2021, 12:05am UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/8 "2021-11-24T00:05:59Z")

</div>

It seems that I have not paused the animation correctly…

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/5/c59a0f8b31d52359a2cb3f5b3a5e10c75fddd9b0.png)  
^ That is the idle animation of my main character… Is there a global way to destroy/stop all animations in the scene? 😃 Currently trying to do this in every turn and it is not doing the trick:

```auto
let animations: AnimationGroup[] = task.loadedAnimationGroups
if (animations && animations.length > 0) {
  animations.forEach((animationGroup: AnimationGroup) => {
    animationGroup.stop()
  })
}

```

Seems as if the initial animations cannot be stopped… Weird.

But yeah there is also the Recast thing I would like to get some insight on 🙂

---

<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:** [November 24, 2021, 12:57am UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/9 "2021-11-24T00:57:22Z")

</div>

scene.stopAllAnimations() should do

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [November 24, 2021, 9:17am UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/10 "2021-11-24T09:17:54Z")

</div>

Are you using the latest version of recast available?  
Can you try to set the recast update time step to 0 (with `setTimeStep`) and profile again?

> **[RecastJSPlugin | Babylon.js Documentation](https://doc.babylonjs.com/typedoc/classes/babylon.recastjsplugin#settimestep)**
>
> RecastJS navigation plugin \[API\]

To improve quality, it’s possible to split deltaTime into smaller substeps. This might be the reason for the time spent here.

---

<div class="post-metadata">

**Author:** ![Panuchka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/panuchka/32/12054_2.png) [@Panuchka](https://forum.babylonjs.com/u/Panuchka)\
**Post date:** [November 24, 2021, 10:27am UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/11 "2021-11-24T10:27:20Z")

</div>

I’ve updated the Recast two months ago in my project, has it received soma major updates? I’m already using the setTimeStep with 0 🙂

```auto
const r = await Recast()
navigation = new RecastJSPlugin(r)
navigation.setTimeStep(0)

```

Could this have something to do with the quite large navmesh area I have?

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [November 24, 2021, 10:32am UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/12 "2021-11-24T10:32:33Z")

</div>

I’ve updated the npm package some weeks ago. If you have no agent, do you have the same trace?

---

<div class="post-metadata">

**Author:** ![Panuchka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/panuchka/32/12054_2.png) [@Panuchka](https://forum.babylonjs.com/u/Panuchka)\
**Post date:** [November 24, 2021, 11:53am UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/13 "2021-11-24T11:53:26Z")

</div>

Removing the agent did give a small 0.3ms boost to the Recast calculations… My crowd is initialized like this:

```auto
crowd = navigation.createCrowd(100, 0.1, scene)

```

Here is the current graph, without agents:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/2/c/2cc5654e89cf6f859b4122680a02ca3cd4d4aa0b.png)

Do you think the newer Recast version could help with performance?

Also I noticed that I should probably strip the models off their materials… Don’t really need the PBR calculations on the server side, right? 😅 Is there some global way to do this, or do I have to tinker with the models by hand?

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [November 24, 2021, 12:39pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/14 "2021-11-24T12:39:04Z")

</div>

yes, test with latest version, to be sure.

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [November 24, 2021, 12:51pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/15 "2021-11-24T12:51:01Z")

</div>

wait, recast update takes roughly twice the time of NullEngine.GetRenderHeight? how much time is it?

---

<div class="post-metadata">

**Author:** ![Panuchka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/panuchka/32/12054_2.png) [@Panuchka](https://forum.babylonjs.com/u/Panuchka)\
**Post date:** [November 24, 2021, 1:15pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/16 "2021-11-24T13:15:09Z")

</div>

Now that I tried again it is around 0.4ms for the update without any agents:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/c/5c3e6765f14c7c15cef78abad32fbf63ecb17490.png)  
Total renderloop time is 0.9ms.

---

<div class="post-metadata">

**Author:** ![Panuchka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/panuchka/32/12054_2.png) [@Panuchka](https://forum.babylonjs.com/u/Panuchka)\
**Post date:** [November 24, 2021, 3:01pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/17 "2021-11-24T15:01:42Z")

</div>

It seems that the performance is a lot better with the new version of recast-detour. This is with the agents involved! 🙂

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/a/8a839d06e9603f247045c76eb696c5bf01405103.png)

0.3ms renderloop time woop woop!

---

<div class="post-metadata">

**Author:** ![Panuchka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/panuchka/32/12054_2.png) [@Panuchka](https://forum.babylonjs.com/u/Panuchka)\
**Post date:** [November 24, 2021, 7:04pm UTC](https://forum.babylonjs.com/t/determining-nullengine-fps/25516/18 "2021-11-24T19:04:07Z")

</div>

All in all this was a pretty cool investigation. If someone stumbles here trying to debug the NullEngine, some tips:

- Use the `engine.getFps().toFixed() ` to get the fps
- Use the `node --inspect` handle to start Node.js in debug mode, then you can use the Chrome devtools to debug your Babylon stuff.
- Do not use actual models/meshes in server side / NullEngine unless it is needed for some reason, for example I have map tiles that are shaped in certain way and cannot be substituted with placeholder meshes.
- Stop the animations of the loaded models and make sure they are stopped. No need to animate models server side, but they might auto-play when imported.
- Remove expensive materials (pbr in my case) from loaded models.
- Try to think if you can `freezeActiveMeshes` on the server side. For example, my game map is composed of a lot of instanced meshes, so I could easily freeze them after creation.

Also use the latest package versions at all times 😉  
Thank you @sebavan and @Cedric for your time and help as well! 🙏 ❤
