Microprofiler showing anchor and cframe taking serveral ms

I’m making a voxel destruction system and part of it requires spawning debris on the client, I’ve been testing it out but sometimes i get huge lag spikes and it seems to be from the fact that the anchor and cframe setters seemingly take forever. I would show the code but it’s a bit complex and i’m not sure how relevant it is to the problem. Any help would be great!

How are you handling the Calculation for the Position ? Do you do it for each part and immediately set the Cframe of said part or do you calculate every position and then batch change Cframes ?

EDIT 1 : also avoid Anchoring and Unanchoring part frequently as it involve complex stuff you don’t want for efficiency

EDIT 2 : If your debris system is constantly creating and destroying parts, you might want to pool the debris objects. Instead of creating new parts every time, you can reuse a set of pre-created parts.

I do actually use part cache for this system and I’ve moved to batch deleting parts, however. I think these lag spikes actually stem from physics, although I’m not sure.

1 Like

I actually have no idea how to debug this :sweat_smile: