How to stop render in HighlightLayer?

const hl = new HighlightLayer('hl', scene, {isStroke:true, mainTextureFixedSize:2048, camera:camera});

When highilghtLayer is done, and setting isEnabled to false, is that mean highilghtLayer stop rendering?
I tried to hl.dispose(), but it could’t be disposed

hl.isEnabled = false

It seems that highilghtLayer still work. How to stop it correctly and no longer render?

Do you mind creating a repro in the Playground so we can see it and try to help?

These two PG add 15000 spheres in scene, and create a HilghlightLayer, and setting highlightLayer .isEnabled = false in 3000 ms. The different is that one PG its sphere meshes were all push into excluded list, the other PG do nothing.

When highlightLayer got disable, i found the PG which using function HilghlightLayer.addExcludedMesh() got lower FPS. Always 1~2 fps different.

Test GPU: RTX 3060Ti
CPU: i7-12700

https://playground.babylonjs.com/#1KUJ0A#2492

lower pfs → https://playground.babylonjs.com/#1KUJ0A#2493

cc @sebavan

dispose should prevent any kind of costs is it not what you are experiencing ?

Dispose is not good while it was high frequence use. I hope to pause highlightlayer rendering when i need, and start rendering also. When setting isEnabled = false,the layer still works?In large scene,this setting reduce performance more obvious?

ok I was concerned dispose was not working, thanks for confirming it is only not usable in your case.

The other part is strange cause Babylon.js/packages/dev/core/src/Layers/effectLayer.ts at master · BabylonJS/Babylon.js · GitHub should prevent the render in the texture which I do not see in spector and the final blit.

Did you check in a perf profile where the culprit lies ? your example are crashing my box :slight_smile:

In fact,i found same issue in SsrRenderpipeline and GlowLayer. I am not sure if it’s the same problem. I will test in some days

Can you share a perf capture ? or share a pg with only 1000 elements

New PG with 1000 elements. Maybe it’s too few elements to detect

the only extra code is running for the excluded meshes:

We should not unhook rehook due to the high memory cost of those functions.

Could you share more about your use case cause a glow layer might not have this inconvenient as it does not rely on stencil.

Thanks everyone for helping, but which one is final solution?

Using a glow layer would be more beneficial in this case if possible.

Another trick is to rely on rendering groups instead of Excluded Meshes.

Hence the final question about the use case to see what would best fit.