Scene.render() vs Engine.runRenderLoop

I am trying to understand a piece of code involving scene.render()
We have a scene. Use click a button. A new mesh appears or disappears from the scene.
When the user click the button and holds it, this makes meshes appear and disappear very fast.

Previously we had


after every event. This was lagging.
Now we have

const renderLoop = () => {
      this._scene.onAfterRenderObservable.addOnce(() => {

And it is not lagging.

I am looking at different examples, the documentation and forum posts, but I still can not understand why the first one makes the scene lag and generally what is the difference between scene.render() and calling scene.render() in a renderLoop.

Would scene.render() render the scene if there are 0 render loops in the engine?
Is there are drawback of having 2-3 render loops that are all calling scene.render()?
I read the runRenderLoop and stopRenderLoop are expensive but I could not find more details of how expensive they are. I look at pars of the code for them and it is adding functions to an array. I think it is the content of the loop that is expensive.

I wonder what am I missing? Why could scene.render() be lagging for us and render loop is working?


I think we would need a repro PG to be able to help.

Essentially, runRenderLoop calls scene.render(), there’s not much besides that, so there should not be any difference between calling scene.render() in the render loop or in your custom loop.

Thanks. I was thinking the same - that it should not be different. I will try to see if I could add a reproduce in a PG