Scene.render() vs Engine.runRenderLoop

Hi,
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

scene.render()

after every event. This was lagging.
Now we have

const renderLoop = () => {
        this._scene.render();
      };
      this._scene.onAfterRenderObservable.addOnce(() => {
        this._scene.getEngine().stopRenderLoop(renderLoop);
      });
      this._scene.getEngine().runRenderLoop(renderLoop);

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?

Thanks

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

This topic seems to have been updated by WebGPU + custom render loop not working

If you come across this in a search, you may want to read the newer topic before following the advice here. In particular, note that the newer topic suggests calling two other methods whenever you call Scene.render outside of runRenderLoop