Can the clone function of mesh be more memory effciency?

Hi team,

I knew cloning a mesh from scene share the geometry and texture, which is memory friendly and cool. But when I clone more meshes with thousands of vertices, the memory still goes up rapidly.

From github, mesh.ts,

the clone function returns a new mesh,the constructor shows there is a bunch of deepcopy contents. which includes the material and geometry.

So If there is a further way for save memory when cloning same meshes on the scene?

Heya, that third param to DeepCopy is the doNotCopyList, resulting in geometry and material not being copied for example. IDK about the overall memory issue thou… :slightly_smiling_face:

Do you want to use different materials for the clones? If not, you could use instances instead, which are even more efficient: Instances | Babylon.js Documentation (babylonjs.com)

Hi Blake!
Thank you for your reply. Oh you are right, that part is not deepcopied…
But I tested a mesh from a skined avatar with about 14k triangle and 5 textures(size 1024x1024) using mesh.copy() function. Which takes about 1.5MB memory and 7ms for loading time during the render loop. I wonder what else should be created and takes the memory if the geometry data is shared after cloning process. Because I want to create the avatar during the run time.

Hi carolhmj,
Thank you for your concern. I am using clones for playing some avatars different animations at the same time during the run time. But one clone function takes about 7ms which leads to a increase of the render time. In terms of performance, is there any way to speed up the cloning process?

The only way I can think of to speed it up would be to pre-create a bunch of disabled clones at the beginning and then quickly enable them as needed. :slightly_smiling_face:

This might be a memory leak somewhere, @RavenLee, could you create a tiny repro in the PG so that we can investigate where we duplicate too much ?

Hi @RavenLee just checking in to see if your problem is resolved or if you could provide us with a playground repro :slight_smile: