Could you post the code you did for running these tests?
Creating instances 1000 times.
local Create = require(game.ServerScriptService:WaitForChild("SmartCreate")).Create
local start = os.clock()
for i = 1, 1000 do
Create("Part", {
Name = "Smart",
Parent = workspace,
Color = Color3.fromRGB(255,255,255),
CFrame = CFrame.new(1,10,0),
Anchored = true,
CanCollide = true,
Size = Vector3.new(2,10,2),
Attributes = {
["IsTouched"] = false,
["DefaultSize"] = Vector3.one,
},
Touched = function(otherPart)
print(otherPart.Name .. " touched!")
end,
Children = {
Create("Part", {
Name = "Head",
Size = Vector3.new(5,5,5),
Anchored = true
})
}
})
end
print(os.clock() - start .. ": SmartCreate's time")
local start = os.clock()
for i = 1, 1000 do
--Setting the property of part
local Part = Instance.new("Part")
Part.Name = "Smart"
Part.Color = Color3.fromRGB(255,255,255)
Part.CFrame = CFrame.new(1,10,0)
Part.Anchored = true
Part.CanCollide = true
Part.Size = Vector3.new(2,10,2)
--Setting the attributes of part
Part:SetAttribute("IsTouched", false)
Part:SetAttribute("DefaultSize", Vector3.one)
--Setting the Touched Event of the part
Part.Touched:Connect(function(otherPart)
print(otherPart.Name .. " touched!")
end)
--Setting the child of the part
local Head = Instance.new("Part")
Head.Name = "Head"
Head.Size = Vector3.new(5,5,5)
Head.Anchored = true
Head.Parent = Part
Part.Parent = workspace
end
print(os.clock() - start .. ": Roblox's time")
With smart create, you set the Parent early on. Try setting the variables in the same order for both and see if it makes a difference
In the code for smart create parent is always set last.
Ok, if you reverse the order. I feel like the results are very inconsistent
code:
local Create = require(game.ReplicatedStorage.Packages:WaitForChild("SmartCreate")).Create
task.wait(5)
local start = os.clock()
for i = 1, 1000 do
--Setting the property of part
local Part = Instance.new("Part")
Part.Name = "Smart"
Part.Color = Color3.fromRGB(255,255,255)
Part.CFrame = CFrame.new(1,10,0)
Part.Anchored = true
Part.CanCollide = true
Part.Size = Vector3.new(2,10,2)
--Setting the attributes of part
Part:SetAttribute("IsTouched", false)
Part:SetAttribute("DefaultSize", Vector3.one)
--Setting the Touched Event of the part
Part.Touched:Connect(function(otherPart)
print(otherPart.Name .. " touched!")
end)
--Setting the child of the part
local Head = Instance.new("Part")
Head.Name = "Head"
Head.Size = Vector3.new(5,5,5)
Head.Anchored = true
Head.Parent = Part
Part.Parent = workspace
end
print(os.clock() - start .. ": Roblox's time")
task.wait(5)
local start = os.clock()
for i = 1, 1000 do
Create("Part", {
Name = "Smart",
Parent = workspace,
Color = Color3.fromRGB(255,255,255),
CFrame = CFrame.new(1,10,0),
Anchored = true,
CanCollide = true,
Size = Vector3.new(2,10,2),
Attributes = {
["IsTouched"] = false,
["DefaultSize"] = Vector3.one,
},
Touched = function(otherPart)
print(otherPart.Name .. " touched!")
end,
Children = {
Create("Part", {
Name = "Head",
Size = Vector3.new(5,5,5),
Anchored = true
})
},
})
end
print(os.clock() - start .. ": SmartCreate's time")
Thatâs why SmartCreate isnât faster they are the same the difference is negligible.
Ok, reverse that and Robloxâs time will be faster.
I am running it on 2 different scripts
Ok, so I conclude the discussion by saying that SmartCreate and Instance.new() are pretty much the same in terms of speed. There are cases where SmartCreate is faster than Instance.new(), and vice versa.
The true intention of this module was to make a Lua version of @rbxts/altmake - npm. I disliked the idea of having multiple lines of code just to customize 1 instance. With SmartCreate I can use 1 function to bulk update an instance.
Your module is already using instance.new internally
local Create = function(ClassName: string, Properties: Properties)
local Object = Instance.new(ClassName)
Edit(Object, Properties)
return Object
end
There is thereby no way it can be any faster than Instance.new() Not only that, but the Edit function for changing the properties also has a lot of code that wouldnât be ran normally.
If you want to speed up setting the same properties on lots of parts, you should instead use the clone method. That is faster when it comes to lots of properties.
I agree, I do not believe that SmartCreate is faster than Instance.new() since it uses Instance.new(). But when I just ran some random tests for just creating 1 instance, I found some how the SmartCreate was faster. Overall I have concluded this discussion here
You guys care about picosecond gains in something that honestly should be taken for what it is: it looks less messy than Instance.new
and property setting.
Some recommendations though:
Hold off the Parent variable until the for loop is closed in the Edit function. Parent should never be set before properties and events are ready.
Allow Properties.Children to expect Instance
or Instance[]
. This is really just a way to clean up curly brace hell for just a single property.
For events, automatically pass the Object itself. For example:
Touched: (object: Instance, hit: Instance) => void
Usually when events happen, the developer modifies the Instance in question. You cannot get that information from automatically hooked up things.
Automatically disconnect events for when the Instance is destroyed. QOL waiting for Roblox to just⌠do this themselves.
Itâs cool to see yet another way of creating Instances, honestly ever since Fusion came out, these seem to of gotten way more popular. A while ago I made something like this for TypeScript, honestly didnât know altmake even existed.
I wouldnât have made it a big deal if it didnât market itself as being faster lol although logically impossible.
This is already done if you actually check out the code.
Personally I wouldnât use it but I could see why people might want to.
Yea, altmake was the main reason I wanted a Lua version. I usually use Roblox-ts, and when I had to use Lua for a project I missed the altmake functionality.
No, itâs not. ^^
Even though Properties.Parent gets set as a variable it is not stopped from being set from the Properties for loop. There is no filter stopping it from being included in there.
Itâs actually set twice.
Itâs not set twice because it is removed from properties beforehand.
How so? The code doesnât do anything differently, properties are set the same and everything as the normal method would go.
Youâre right, I donât know how I overlooked those lines. Honestly I read Properties on that line to be the Object itself, which didnât make sense in my head
I canât confirm that this is faster than robloxâs one, did a few runs using the Benchmarker plugin
this is the code ran (make sure it has the .bench
at the end of the modulescript name)
--[[
This file is for use by Benchmarker (https://boatbomber.itch.io/benchmarker)
|WARNING| THIS RUNS IN YOUR REAL ENVIRONMENT. |WARNING|
--]]
return {
ParameterGenerator = function()
return
end,
Functions = {
["SmartCreate"] = function(Profiler)
local Create = require(game.ServerScriptService:WaitForChild("SmartCreate")).Create
local part = Create("Part", {
Name = "Smart",
Parent = workspace,
Color = Color3.fromRGB(255,255,255),
CFrame = CFrame.new(1,10,0),
Anchored = true,
CanCollide = true,
Size = Vector3.new(2,10,2),
Attributes = {
["IsTouched"] = false,
["DefaultSize"] = Vector3.one,
},
Touched = function(otherPart)
print(otherPart.Name .. " touched!")
end,
Children = {
Create("Part", {
Name = "Head",
Size = Vector3.new(5,5,5),
Anchored = true
})
}
})
part:Destroy() -- so the workspace doesn't get messy
end,
["Roblox"] = function(Profiler)
--Setting the property of part
local Part = Instance.new("Part")
Part.Name = "Smart"
Part.Color = Color3.fromRGB(255,255,255)
Part.CFrame = CFrame.new(1,10,0)
Part.Anchored = true
Part.CanCollide = true
Part.Size = Vector3.new(2,10,2)
--Setting the attributes of part
Part:SetAttribute("IsTouched", false)
Part:SetAttribute("DefaultSize", Vector3.one)
--Setting the Touched Event of the part
Part.Touched:Connect(function(otherPart)
print(otherPart.Name .. " touched!")
end)
--Setting the child of the part
local Head = Instance.new("Part")
Head.Name = "Head"
Head.Size = Vector3.new(5,5,5)
Head.Anchored = true
Head.Parent = Part
Part.Parent = workspace
Part:Destroy()
end,
},
}
also I still wouldnât use it as nobody cares if itâs a few Îźs faster as weâre in 2023 now, not in 1986
use the benchmarker plugin instead of desmos (it costs 18.36 AED but donât worry about the price as itâs not too expensive (18.36 AED = 5 USD), also itâs on itch.io cuz boatbomber hates the plugin marketplace being toxic)
wow bro will i encounter 1k+ parts spawning irl?
Yet again. This resource shouldnât be promoting that its faster than instance.new because even if it was, it does not matter if its a few microseconds faster and it uses instance.new internally so it cant be âfasterâ