Switch from mock Vector3 to native vector lib

This commit is contained in:
aaron 2024-11-13 22:35:16 +00:00
parent 5abd5eee91
commit 49cc551493
5 changed files with 52 additions and 95 deletions

View file

@ -504,85 +504,78 @@ ROOT_BENCH(`get context (depth={depth})`, function()
end)
end)
N *= 1024
TITLE "spring()"
ROOT_BENCH("spring update", function()
local root, source, spring = vide.root, vide.source, vide.spring
local src = source(0)
root(function()
for i = 1, N do
spring(src)
end
START(N)
src(1)
return nil
end)
end)
ROOT_BENCH("spring step", function()
local root, source, spring = vide.root, vide.source, vide.spring
local src = source(0)
root(function()
for i = 1, N do
spring(src)
end
src(1)
START(N)
vide.step(1/60)
return nil
end)
end)
TITLE "aggregate"
do
-- the purpose of the two following benchmarks is to measure the overhead of
-- aggregate construction
ROOT_BENCH("set explicit mock vector2", function()
ROOT_BENCH("set explicit vector", function()
local apply = require "../src/apply"
local Vector2 = require "../test/mock".Vector2
local label = create "TextLabel" {
AnchorPoint = Vector2.new(1, 1)
AnchorPoint = vector.create(1, 1, 1)
}
for i = 1, START(N) do
apply(label, {
AnchorPoint = Vector2.new(i, i)
AnchorPoint = vector.create(i, i, i)
})
end
end)
ROOT_BENCH("set aggregate mock vector2", function()
ROOT_BENCH("set aggregate vector", function()
local apply = require "../src/apply"
local Vector2 = require "../test/mock".Vector2
local label = create "TextLabel" {
AnchorPoint = Vector2.new(1, 1)
AnchorPoint = vector.create(1, 1, 1)
}
for i = 1, START(N) do
apply(label, {
AnchorPoint = { i, i }
AnchorPoint = { i, i, i }
})
end
end)
end
-- innacurate due to no Vector3 in vanilla Luau
-- mock vector is 200x slower than native vector
-- ROOT_BENCH("spring update", function()
-- local root, source, spring = vide.root, vide.source, vide.spring
-- local src = source(0)
-- root(function()
-- for i = 1, N do
-- spring(src)
-- end
-- START(N)
-- src(1)
-- return nil
-- end)
-- end)
-- N /= 1024
-- ROOT_BENCH("spring step", function()
-- local root, source, spring = vide.root, vide.source, vide.spring
-- local src = source(0)
-- root(function()
-- for i = 1, N do
-- spring(src)
-- end
-- src(1)
-- START(N)
-- vide.step(1/60)
-- return nil
-- end)
-- end)
return nil

View file

@ -257,40 +257,6 @@ local Vector2 = { __type = "Vector2" } :: any do
end
end
local Vector3 = { __type = "Vector3" } :: any do
local function new(x, y, z)
return setmetatable({ X = x, Y = y, Z = z }, Vector3)
end
function Vector3.new(x, y, z)
return new(x or 0, y or 0, z or 0)
end
function Vector3.__add(a, b)
return new(a.X + b.X, a.Y + b.Y, a.Z + b.Z)
end
function Vector3.__sub(a, b)
return new(a.X - b.X, a.Y - b.Y, a.Z - b.Z)
end
function Vector3.__mul(a, b)
return new(a.X * b, a.Y * b, a.Z * b)
end
function Vector3.__unm(v)
return new(-v.X, -v.Y, -v.Z)
end
function Vector3.__eq(a, b)
return a.X == b.X and a.Y == b.Y
end
function Vector3.__index(v)
return (v.X^2 + v.Y^2 + v.Z^2)^0.5
end
end
local UDim2 = { __type = "UDim2" } :: any do
function UDim2.new(sx, ox, sy, oy)
return table_to_proxy(setmetatable({ x = { scale = sx, offset = ox }, y = { scale = sy, offset = oy } }, UDim2))
@ -330,7 +296,6 @@ return {
Instance = Instance :: typeof(Instance),
Color3 = Color3 :: typeof(Color3),
Vector2 = Vector2 :: typeof(Vector2),
Vector3 = Vector3 :: typeof(Vector3),
UDim2 = UDim2 :: typeof(UDim2),
Enum = Enum :: typeof(Enum),
typeof = typeof :: typeof(typeof)