Artificially limiting framerate

I have a real-time ML model executing on GPU using WebGL and its always competing with resources with BabylonJS scene that visualizes results from the model.

When ML model is paused, babylon both engine.getFps() and engine.performanceMonitor.averageFPS return ~144 which is a refresh rate of my display.

When model is running, that drops to ~20 fps.

But the thing is, there are different user scenarios:
a) smooth visualization or b) as-fast-as-possible ML results.

for (a) I know how to slow down ML processing
and that does free up resources so babylon fps rendering speeds up

for (b) Question is how can I artificially slow down babylon rendering loop
(to lets say target of 5FPS) to free up as much resources as possible for ML?

I’ve looked at engine timeStep option, but that doesn’t appear to do the trick.
And using scene optimizer is exactly the opposite of what I need.

I do not know what ML is, but here goes. Fun fact, I do not believe you have to have an actual render “LOOP” for BJS. You just need to call scene.render(). If you have a different process which runs over and over that is used for input to a scene, seems like you could just put the render at the end.

Probably, not going to dramatically increase rates, there is only so much time in a second. Would eliminate un- necessary render when the “input” has not changed yet.

1 Like

Wouldn’t the simplest way just be when in that low FPS mode mode, in your render loop check if lastTickTime + some ms constant is < currentTime and don’t perform whatever logic/render until then

I do not know what ML is

ml = machine learning

ok, i’ve replaced:

engine.runRenderLoop(() => scene.render());

with something like:

const targetFps = 5;
setInterval(() => scene.render(), 1000 / targetFps);

and that gives me visual ~5fps which is exactly what i needed
and if i need to change targetFps, i can do a clearInterval and set a new one

only side-effects are that engine.getFps() now returns fixed 60 no matter what and engine.performanceMonitor.averageFPS is Infinity

ideally, there would be a engine.setFps() method, but i can work with this