Using Instance.new("class", **parent**) on the **client** isn't that bad?

This is really tripping me out. I have a software renderer that basically creates a lot of frames at the beginning of my program but that’s it, it just puts them into an array and it doesn’t talk to anyone else but the client. All scripts are on the client, this is completely clientside. I found out that the difference over like 3 tests was only about half a second at 200x200 resolution (which takes about 15 seconds to run regardless). Is this like some neat caveat with it or something?


local i =0
local start = os.clock()
for x=0,width-1 do
	backbuffer[x] = {}
	zbuffer[x] = {}
	for y=0,height-1 do
		i += 1
		if i % 1000 == 0 then
			game:GetService("RunService").Heartbeat:Wait()
		end
		local pixel = Instance.new("Frame", script.Parent.Canvas)
		pixel.BorderSizePixel = 0
		pixel.BackgroundColor3 = Color3.new()
		pixel.Position = UDim2.fromScale((width-x)/width,y/height)
		pixel.Size = UDim2.fromScale(1/width, 1/height)
		backbuffer[x][y] = {texture:sample(Vector2.new(x/width,y/height)), pixel}
		zbuffer[x][y] = -math.huge
	end
end
print(os.clock() - start)
2 Likes

I found this on the Developer Hub:

Performance note: When the Parent of an object is set, Roblox begins listening to a variety of different property changes for replication, rendering and physics. Therefore, it is recommended to set the Parent property last when creating new objects. As such, you should avoid using the second argument ( parent ) of this function. You can read this thread on the developer forum for more information.

Which refers to a new thread on this forum about the parent argument of Instance.new. Long story short, it is best practice to set the parent after all properties of a new object are set. This is the best option in terms of performance.

4 Likes