Huge performance spike

I’ve implemented a object pool to create objects in runtime.
However still exists a performance problem.


I just set obj.enabled as true and reposition the objects.

Am I wrong with it?

Can you provide a link to the project? Is this all the way through the app or just at the start?


this causes everytime I use the pool. (not only start)
target object has 1,643 tris mesh and one sprite.

Here’s my testcode:

Press the ARROW_UP to create an object and first three objects will use cache.
(See the Prefab.preload)



My guess is that when you enable the entities, it adds the meshes to the render layer/list looking at the model component source code.

I can explain what you are seeing here. When you enable your object, it is rendered for the first time. But the shader for the object needs to be compiled. The first function to get information from the shader is getShaderParameter. But because the shader is still compiling and linking, the function waits until that is done.

WebGL doesn’t allow applications to load precompiled shader binaries. They must be compiled every time the application is run.

However, we are currently investigating a system which allows you to record the shaders your application uses and then request them all to be compiled as soon as the application starts.

Another way to avoid shaders being compiled during gameplay is to force all objects to be rendered on the first frame of your game and then immediately disable the ones you don’t need.

It’s been 3 years, do we have the system you mentioned in PlayCanvas?

There is an unofficial system that could help here: Optimising texture usage - #14 by mvaligursky

But it’s not fully finished / guaranteed to work.

What problems are you facing?

1 Like

The same problem as this post owner. I have to render all models on the first frame to prevent high compile shader time on iOS (with Apple’s GPU). It’s not a good practice and cost me huge development time.

The mentioned dumpPrograms is the only other option at the moment. We’re starting the work on shader system refactoring to make many things easier, and to improve this is one of the side objectives, so fingers crossed in the future.


I’m currently facing this issue, but I’m not adding any new models or shaders mid game. The game loads up, adds in all the objects, and then I’ll randomly get an animation frame mid game that takes 200+ms due to getShaderParameter.


The issue is that the shaders don’t get compiled until they are first rendered so even if you don’t add any at runtime, you can still be subject to stalls while they are compiled for the first time.

Ways to mitigate this:

  1. If you only have a few lights that don’t change at runtime, try disabling clustered lighting in Project Settings → Rendering. There are some issues around DirectX renderer and Windows that can cause extended compile times with clustered lighting.

  2. If you can get away with no shadows on omni and directional spotlights, disable shadows from clustered lighting in Project Settings → Rendering. This will reduce the size of the shader to compile.

  3. Force shader compiling upfront by having a frame of rendering where all the materials are rendered for a frame. Some developers have a space where all the materials are on cubes and a second camera that is enabled for the first frame only. See this thread for an example: [SOLVED] Application will stutter in the Intro Animation - #21 by Vahrenhol3D

1 Like