I hope the same optimization will be done to other value types like CFrames, UDim2 and Vector2.
The performance gains are quite significant:
local cl = os.clock()
local vec3 = Vector3.new()
for i = 1, 10^7 do
vec3+=Vector3.new(i,i,i)
end
print("Vector3 addition: ", os.clock()-cl)
local cl = os.clock()
local vec2 = Vector2.new()
for i = 1, 10^7 do
math.random(0,i)
vec2+=Vector2.new(i,i)
end
print("Vector2 addition: "..os.clock()-cl)
local cl = os.clock()
local cf = CFrame.new()
for i = 1, 10^7 do
cf+=Vector3.new(i,i,i)
end
print("CFrame/Vector3 addition: "..os.clock()-cl)
local cl = os.clock()
local cf = CFrame.new()
for i = 1, 10^7 do
cf*=CFrame.new(i,i,i)
end
print("CFrame Multiplication: "..os.clock()-cl)
The resulting benchmarks with the old Vector3s:
Vector3 addition: 1.6341197000002
Vector2 addition: 1.8228185999906
CFrame/Vector3 addition: 1.6889015000197
CFrame Multiplication: 1.8462797999964
The same with the new Vector3s:
Vector3 addition: 0.26172300000326
Vector2 addition: 1.8144201000105
CFrame/Vector3 addition: 1.0896642000007
CFrame Multiplication: 1.8471370000043
Vector2 maths are now significantly slower than the native Vector3s.
CFrame math is quite a bit faster as long as it involves Vector3s but are otherwise just as fast/slow as before.
I hope that that the same/similar optimizations will be done to CFrames especially.