BABYLON.MeshBuilder.CreateBox cost long time

i build a mesh group(c-Mesh) contains a cube & a line;

   for(var i = 0;i<1000;i++){
       build c-Mesh

because the API is synchronous
so,that costed 30+ seconds
i wonder Is there any way to optimize


Have you tried to use clone instead of creating a new cube/line each time?


I used a variable to control the render and turn it on after the creation

    if (this.running) {

I hope this will increase the speed of creation,But it doesn’t seem to work

Finally, I cleared all the elements every time I created a batch, and the speed increased

I thought, I use a switch to control the render, so the number of elements in the scene should not affect the speed of the JS thread

Maybe I should see how Babylon works

When doing:

   for(var i = 0;i<1000;i++){
       build c-Mesh

it is done synchronously, meaning the loop is done before going on. So, stopping to render has no effect, as the rendering code is not executed during the duration of the loop anyway.

I think you should setup a repro in the playground if you want people to be able to help you more.

ok,i created a PG:

and,i found some articles:


It looks as if elements can take up CPU resources even if they are invisible

I’m not sure I understand what is your problem: is it that creating the meshes is slow or is it displaying them which is slow? The screenshot above is for optimizing the display, not the creation.

So let’s just ignore this screenshot,

have you see the PG,
I created 1000 invisible elements,cost 2700ms;
then i created 2000 invisible elements,cost 16800ms;

i just think it looks as if elements can take up CPU resources even if they are invisible

It takes around 120ms on my computer to create the 1000 elements and 240ms for the 2000 other elements if I uncomment the code lines 15-19, so everything seems ok to me.

Maybe you hit some memory barriers on your computer (even if creating 3000 elements should not take that much)?

emm…what version did you used?

when i use the version 5.0,i got the same result:

the version 4.2 can’t work well on my computer now,so i can’t got the screenshot

Yes, I’m using 5.0.

Maybe there were some problems in 4.2 to deal with such cases…