Using 'instantiateRenderEntity' function freeze the frames

Hi everyone! I loaded the glb files using the container asset and create an entity using the “instantiateRenderEntity” function.

I’ve noticed that when using low CPU devices (also test on the Chrome performance dev tool set to 6x slowdown), the “instantiateRenderEntity” function freezes the frame for a while. My assumption is that this happens because the “cloneHierarchy” function within “instantiateRenderEntity” takes time to loop through all the nodes in the complex model.

Does anyone face the same situation? :thinking:
Any ideas on how to avoid this freeze in such cases

const entity = asset.resource.instantiateRenderEntity();
const rootEntity = new pc.Entity(name);
rootEntity.addChild(entity);

Thank you.

Most probably a freeze is coming from the need to compile the shader for your new model material. A workaround would be to render a primitive, say a box, with this material at app start for one frame, then hide it. So when you model appears mid-game, the shader would be compiled already.

add this somewhere to your script at start up, to see if the shader compilation is expensive for you, and how many shaders it compiles

pc.Tracing.set(pc.TRACEID_SHADER_COMPILE, true);

Thank you so much! I will try to look at the shaders.