With this PR, three.js v158 supports a compileAsync method which can compile shaders and return a Promise that resolves when they're ready.
Taking the Frosted glass example, my M1 Macbook spends several frames (74.6ms in total) blocked on shader compilation.

This new method sounds like a good fit for react-three-fiber's ability to leverage React's lifecycle management, to Suspend during compilation, then attach the objects to the scene.
Taking a step back, in my applications I don't mind if the 3D components 'arrive' a few frames later, but this kind of blocking of the main thread is visually noticeable.
I'm not too familiar with the internals of three or r3f at this level but I'd be happy to contribute, given some pointers in the right direction.
- Should the Preload component in Drei handle this?
- Is moving the minimum three.js version to v158 a breaking change for Drei?
- Is changing Preload to have it suspend a breaking change?
- Should there be a new component in Drei where the children are compiled asynchronously, and only added to the 'real' scene when compilation has completed?
- Should this just be the default behaviour for everything, and built into the r3f reconciler itself?
- How does this work in the context of something like the MeshTransmissionMaterial making its own calls to
gl.render?
From what I can tell, this will only be an improvement for non-firefox browsers, due to the availability of the KHR_parallel_shader_compile extension.
With this PR, three.js v158 supports a
compileAsyncmethod which can compile shaders and return a Promise that resolves when they're ready.Taking the Frosted glass example, my M1 Macbook spends several frames (74.6ms in total) blocked on shader compilation.
This new method sounds like a good fit for react-three-fiber's ability to leverage React's lifecycle management, to Suspend during compilation, then attach the objects to the scene.
Taking a step back, in my applications I don't mind if the 3D components 'arrive' a few frames later, but this kind of blocking of the main thread is visually noticeable.
I'm not too familiar with the internals of three or r3f at this level but I'd be happy to contribute, given some pointers in the right direction.
gl.render?From what I can tell, this will only be an improvement for non-firefox browsers, due to the availability of the KHR_parallel_shader_compile extension.