Inconsistent Frame Rate


I have been building an action game with Babylon and so far am loving it!

One issue I have found however is that the framerate can be somewhat inconsistent. I get 500+ absolute frames and a “general” 120 frames, but there seem to be some spikes that drop the framerate (only slightly) to around 100 for the bottom 5% of frames.

However, this change is enough to lead to some jaggedness in the movement/combat in my game.

I have tried to debug and the only things that look like they might cause these issues are Major GC (which I know is uncontrollable) and some large Event:PointerMove execution times.

I have tried using lockstep, but I find that the rendering and lockstep difference can lead to some similar jagged movement as described above.

If anyone knows how I could improve the consistency of my framerate I would appreciate it.

EDIT: One thing I have found to help is to smooth the delta time over 5 frames to prevent “spiky” movement but this is only a partial solution really?

Welcome aboard!

Regarding the large time spent in PointerMove, maybe it’s related to picking? By default, picking is enabled for all meshes. Maybe you can disable it if you don’t need it, or disable/enable it when really needed?

GC can indeed take some time, and we try in Babylon.js to limit it as much as possible. I don’t know if there are tools in the browser for that, but it would be interesting to know which objects are garbage collected during a GC and see if we can do something about it.

Also, did you see this doc page?



Thanks for your reply! In terms of the picking I believe you are correct. I was actually picking and completely forgot about it!

I looked into the optimisation page before, I need to change a little bit of my codebase to take advantage of it but I think this should help my ‘Prod’ builds :slight_smile:

Looks like the GC is being triggered very frequently so perhaps I am not using efficient memory patterns. I will take a look!

I would say that anyone looking at this should take advantage of your points and optimise their meshes/use the built-in.
Also look to smooth delta time over a couple of frames to avoid any spikes from GC etc, technically it leads to a less accurate simulation but realistically it makes the experience much smoother! :slight_smile:


I made a discovery after poking around with performance for a while. One thing I found was that the _pickMove on scene._inputManager was being called for pointer movements in my game. It was causing a roughly 5% performance impact on all pointer move ticks (almost every frame for a busy player).

I dug in and found it was not needed for my implementation. _registeredActions in scene was >0 but I had none that needed this functionality. I replaced it with a dummy function for a free perf boost.

I’d suggest checking the functionality around calling _pickMove if you get the chance :slight_smile:

Either way, loving the engine and I will be looking for more perf gains so will let you know how it goes!

If you don’t need the picking functionality, you can set scene.pointerMoveTrianglePredicate = () => false for a perf boost.

However, that is still looping over all meshes of the scene… cc @PolygonalSun in case there’s something we could do about this.

Fairly sure Scene.skipPointerMovePicking does this?

Simular properties exist for pointerUp and pointerDown

You’re right, I forgot about those ones!

Yup, scene.skipPointerMovePicking should outright skip any picking code. Just out of curiosity, @JHines, what version of BJS are you using?

Nice! I didn’t see that :slight_smile: You are totally correct, scene.skipPointerMovePicking does the job. I am currently on 5.42.1, I just didn’t see that variable!