Skip to content

Commit

Permalink
Switch storage strategy (#87)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcus <ukendio@gmail.com>
Co-authored-by: Jack T <jack@jackt.space>
  • Loading branch information
3 people authored Oct 21, 2024
1 parent 18e5b29 commit 4c1dca1
Show file tree
Hide file tree
Showing 15 changed files with 966 additions and 600 deletions.
2 changes: 1 addition & 1 deletion benchmark.project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"$path": "lib"
},
"PinnedMatter": {
"$path": "pinned/Matter_0_8_3.rbxm"
"$path": "pinned/Matter_0_8_4.rbxm"
}
},
"ServerStorage": {
Expand Down
36 changes: 36 additions & 0 deletions benchmarks/insert.bench.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--!optimize 2
--!native
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Matter = require(ReplicatedStorage.Matter)
local PinnedMatter = require(ReplicatedStorage.PinnedMatter)

local A, B = Matter.component(), Matter.component()
local pinnedA, pinnedB = PinnedMatter.component(), PinnedMatter.component()

local N = 500

return {
ParameterGenerator = function()
local world, pinnedWorld = Matter.World.new(), PinnedMatter.World.new()
for i = 1, N do
world:spawnAt(i)
pinnedWorld:spawnAt(i)
end

return world, pinnedWorld
end,

Functions = {
["Matter 0.9"] = function(_, world)
for i = 1, N do
world:insert(i, A({ i }))
end
end,
["Matter 0.8.4"] = function(_, _, world)
for i = 1, N do
world:insert(i, A({ i }))
end
end,
},
}
38 changes: 38 additions & 0 deletions benchmarks/next.bench.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--!optimize 2
--!native
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Matter = require(ReplicatedStorage.Matter)
local PinnedMatter = require(ReplicatedStorage.PinnedMatter)

local world = Matter.World.new()
local pinnedWorld = PinnedMatter.World.new()

local A, B = Matter.component(), Matter.component()
local pinnedA, pinnedB = PinnedMatter.component(), PinnedMatter.component()

for i = 1, 10_000 do
world:spawnAt(i, A({}), B({}))
pinnedWorld:spawnAt(i, pinnedA({}), pinnedB({}))
end

return {
ParameterGenerator = function()
return
end,

Functions = {
["Matter 0.9"] = function()
local query = world:query(A, B)
for _ = 1, 1_000 do
query:next()
end
end,
["Matter 0.8.4"] = function()
local query = pinnedWorld:query(pinnedA, pinnedB)
for _ = 1, 1_000 do
query:next()
end
end,
},
}
4 changes: 2 additions & 2 deletions benchmarks/query.bench.luau
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ return {
end,

Functions = {
["New Matter"] = function()
["Matter 0.9"] = function()
local count = 0
for _ in world:query(A, B) do
count += 1
end
end,
["Old Matter"] = function()
["Matter 0.8.4"] = function()
local count = 0
for _ in pinnedWorld:query(pinnedA, pinnedB) do
count += 1
Expand Down
104 changes: 104 additions & 0 deletions benchmarks/stress.bench.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
--!optimize 2
--!native
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Matter = require(ReplicatedStorage.Matter)
local PinnedMatter = require(ReplicatedStorage.PinnedMatter)

local world = Matter.World.new()
local pinnedWorld = PinnedMatter.World.new()

local A, B, C, D, E, F, G =
Matter.component(),
Matter.component(),
Matter.component(),
Matter.component(),
Matter.component(),
Matter.component(),
Matter.component()
local pinnedA, pinnedB, pinnedC, pinnedD, pinnedE, pinnedF, pinnedG =
PinnedMatter.component(),
PinnedMatter.component(),
PinnedMatter.component(),
PinnedMatter.component(),
PinnedMatter.component(),
PinnedMatter.component(),
PinnedMatter.component()

local function flip()
return math.random() > 0.5
end

local archetypes = {}
for i = 1, 30_000 do
local id = i
world:spawnAt(id)
pinnedWorld:spawnAt(id)

local str = ""
if flip() then
world:insert(id, A({ a = true, id = i }))
pinnedWorld:insert(id, pinnedA({ a = true, id = i }))
str ..= "A_"
end
if flip() then
world:insert(id, B({ b = true, id = i }))
pinnedWorld:insert(id, pinnedB({ b = true, id = i }))
str ..= "B_"
end
if flip() then
world:insert(id, C({ c = true, id = i }))
pinnedWorld:insert(id, pinnedC({ c = true, id = i }))
str ..= "C_"
end
if flip() then
world:insert(id, D({ d = true, id = i }))
pinnedWorld:insert(id, pinnedD({ d = true, id = i }))
str ..= "D_"
end
if flip() then
world:insert(id, E({ e = true, id = i }))
pinnedWorld:insert(id, pinnedE({ e = true, id = i }))
str ..= "E_"
end
if flip() then
world:insert(id, F({ f = true, id = i }))
pinnedWorld:insert(id, pinnedF({ f = true, id = i }))
str ..= "F_"
end
if flip() then
world:insert(id, G({ g = true, id = i }))
pinnedWorld:insert(id, pinnedG({ g = true, id = i }))
str ..= "G"
end

archetypes[str] = (archetypes[str] or 0) + 1
end

local total = 0
for _ in archetypes do
total += 1
end

print(total, "different archetypes")

return {
ParameterGenerator = function()
return
end,

Functions = {
["Matter 0.8.4"] = function()
local count = 0
for _ in pinnedWorld:query(pinnedB, pinnedA) do
count += 1
end
end,
["Matter 0.9"] = function()
local count = 0
for _ in world:query(B, A) do
count += 1
end
end,
},
}
86 changes: 86 additions & 0 deletions benchmarks/without.bench.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
--!optimize 2
--!native
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Matter = require(ReplicatedStorage.Matter)
local PinnedMatter = require(ReplicatedStorage.PinnedMatter)

local world = Matter.World.new()
local pinnedWorld = PinnedMatter.World.new()

local A, B, C, D, E, F, G =
Matter.component(),
Matter.component(),
Matter.component(),
Matter.component(),
Matter.component(),
Matter.component(),
Matter.component()
local pinnedA, pinnedB, pinnedC, pinnedD, pinnedE, pinnedF, pinnedG =
PinnedMatter.component(),
PinnedMatter.component(),
PinnedMatter.component(),
PinnedMatter.component(),
PinnedMatter.component(),
PinnedMatter.component(),
PinnedMatter.component()

local function flip()
return math.random() > 0.5
end

for i = 1, 50_000 do
local id = i
world:spawnAt(id)
pinnedWorld:spawnAt(id)

if flip() then
world:insert(id, A({ a = true, id = i }))
pinnedWorld:insert(id, pinnedA({ a = true, id = i }))
end
if flip() then
world:insert(id, B({ b = true, id = i }))
pinnedWorld:insert(id, pinnedB({ b = true, id = i }))
end
if flip() then
world:insert(id, C({ c = true, id = i }))
pinnedWorld:insert(id, pinnedC({ c = true, id = i }))
end
if flip() then
world:insert(id, D({ d = true, id = i }))
pinnedWorld:insert(id, pinnedD({ d = true, id = i }))
end
if flip() then
world:insert(id, E({ e = true, id = i }))
pinnedWorld:insert(id, pinnedE({ e = true, id = i }))
end
if flip() then
world:insert(id, F({ f = true, id = i }))
pinnedWorld:insert(id, pinnedF({ f = true, id = i }))
end
if flip() then
world:insert(id, G({ g = true, id = i }))
pinnedWorld:insert(id, pinnedG({ g = true, id = i }))
end
end

return {
ParameterGenerator = function()
return
end,

Functions = {
["Matter 0.8.4"] = function()
local count = 0
for _ in pinnedWorld:query(pinnedB):without(pinnedC) do
count += 1
end
end,
["Matter 0.9"] = function()
local count = 0
for _ in world:query(B):without(C) do
count += 1
end
end,
},
}
1 change: 0 additions & 1 deletion lib/Loop.luau
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ function Loop:begin(events)
end

local debugger = self._debugger

if debugger and debugger.debugSystem == system and debugger._queries then
local totalQueryTime = 0

Expand Down
Loading

0 comments on commit 4c1dca1

Please sign in to comment.