:Clone() or :Instance.New()?

Hello, making a gun system here. Replicating a lot of bullets(30 bullets a mag). My question is simple

Does Clone() or Instance.New() create less lag?
Which one is more efficient.
And which one should I use and why?

If both have their perks please do explain.

6 Likes

Personally, I prefer prefabricating and then using :Clone().

It keeps your code cleaner and less cluttered, and I think it’s faster since you don’t have to keep setting the properties every time you create one.

The difference is probably minor, so you could do whichever you prefer without much performance loss.

6 Likes

Clone is faster apparently (Just tested for you with the following code):

local start = tick();
local p = Instance.new'Part';
p.Parent = workspace;
p.Anchored = true;
p.BrickColor = BrickColor.new('Bright red')--adding few properties to test the thing out
p.Locked = true;
print('Part created in '.. tick()-start..' seconds');
start = tick();
local clone = p:Clone();
clone.Parent = workspace;
print('Part cloned in '.. tick()-start..' seconds');

image

5 Likes

Your benchmark is flawed and even if it wasn’t, running it once doesn’t help much. And it’s also incorrect, :Clone is slow.

image
image

And as for OP, you should use PartCache instead. Neither of these are optimal, but PartCache is.

12 Likes

I feel like benchmarking these is absolutely pointless in this scenario because benchmarking isn’t representative of a real world application. Worrying about which one is faster is also pointless, it’s not like you’re saving significant amounts of time.

Just use whichever one is more comfortable for you. Just because one runs slower, doesn’t mean it creates lag. What matters is how you handle those parts later. Ultimately for both cloning and instancing, the new object is just a piece of memory detached from the DataModel that you’re modifying.

Only perk difference I can think of is that you’re going to feel more comfortable with clone because you’re copying something that’s already been made. If you instance the part, then you have to write out all the configurations and all.

18 Likes

Thanks for the info on PartCache, I never knew something like that existed.
I’m not an expert in these things and it might take me alot of time to get familiar with PartCache, Do you think it’s worth learning about it?

It is. Definitely check it out because recreating Instances sucks.

3 Likes

I don’t see a reason for the benchmark to be inaccurate.