Camera's Render Layer : How to warmup to avoid first time lag?

Whe using the object.layers.set(...) for the first time on the camera, I get a small frame freeze then on consecutive calls it works smoothly.

What is the right method to warmup this so when I do need to trigger this for the first time it doesn’t lag? Should I run a dummy round on initialization while showing the loading screen and take that as part of the loading process? Would this be ok or sounds dirty?

I mean, it has something to do with shader recompiling or something, just run a test of instead of changing the camera layer, I changed the layer of everything else and it runs smoothly… might take this as the solution for now.

In my particular case I do want to keep all the camera post processing and state so this is ok. But If I did requird to switch to another camera with other settings, I would run into the same first-time freeze.

So is the standard way to handle this do to a first time render off screen to warmup the cache?

Shaders are compiled on demand when a Mesh first gets rendered, and will block the render until the shader is compiled.

You may be able to use:

https://threejs.org/docs/#api/en/renderers/WebGLRenderer.compile

To force them to compile at startup, assuming they are all added to the scene.