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?
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.
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
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!
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
Either way, loving the engine and I will be looking for more perf gains so will let you know how it goes!