Here’s how I believe debris:AddItem works
Note: I’m going to be talking about soley the speed it takes to reach the point to call the destroy function, not the speed of destroy
There is a priority queue that sorts based on removal time
Every update interval (probably 30 hz) the front of the queue is checked to see if its removal time is <= current time
If it is then remove it and keep repeating this check + remove until removal time >
Removing takes O(lg n), querying top takes O(1)
So clearing the queue for all debris items to remove would be O(n lg n)
As for actually calling the function :AddItem(), it would need to insert removal time (tick()+delay arg) and the object to remove into the priority queue which is O(1)
So this means that using debris:AddItem has a complexity of O(n lg n)
Altnernatively if you were to use delay(delay arg,func()) and destroy like that, the complexity would probably(??) be The same but the fact that you are creating a thread instead of using AddItem might mean there are higher constants since add item is specific to just destroy while delay creates a new thread so it will definitely take more memory too.
But if you were to just call destroy without needing a delay, destroy is the way to go since it’s O(n) for n consecutive destroys while add item is O(n lg n)
Not to mention constant overheads or the fact that add item (I haven’t tested but this is probably true since spawn does this) delays deletion by 1/30 seconds
So if you need delay, use add item, but if you need insta delete, use destroy
IF you already have an extra thread made (wait counts) then just call destroy on that but don’t create a new thread/wait just for destroying an object