diff --git a/benches/visual/spawn.bench.lua b/benches/visual/spawn.bench.lua index 962064e..c5e6aef 100644 --- a/benches/visual/spawn.bench.lua +++ b/benches/visual/spawn.bench.lua @@ -2,41 +2,37 @@ --!native local ReplicatedStorage = game:GetService("ReplicatedStorage") -local rgb = require(ReplicatedStorage.rgb) local Matter = require(ReplicatedStorage.DevPackages.Matter) -local jecs = require(ReplicatedStorage.Lib) local ecr = require(ReplicatedStorage.DevPackages.ecr) +local jecs = require(ReplicatedStorage.Lib) +local rgb = require(ReplicatedStorage.rgb) local newWorld = Matter.World.new() local ecs = jecs.World.new() - return { ParameterGenerator = function() - local registry2 = ecr.registry() + local registry2 = ecr.registry() return registry2 - end, + end; Functions = { - Matter = function() - for i = 1, 1000 do - newWorld:spawn() - end - end, + Matter = function() + for i = 1, 1000 do + newWorld:spawn() + end + end; + ECR = function(_, registry2) + for i = 1, 1000 do + registry2.create() + end + end; - ECR = function(_, registry2) - for i = 1, 1000 do - registry2.create() - end - end, - - - Jecs = function() - for i = 1, 1000 do - ecs:entity() - end - end - - }, + Jecs = function() + for i = 1, 1000 do + ecs:entity() + end + end; + }; } diff --git a/lib/init.lua b/lib/init.lua index 58378f3..644fa78 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -470,9 +470,10 @@ function World.query(world: World, ...: i53): Query local withoutComponents = {...} for index = #compatibleArchetypes, 1, -1 do local archetype = compatibleArchetypes[index][1] + local records = archetype.records local shouldRemove = false for _, componentId in withoutComponents do - if archetype.records[componentId] then + if records[componentId] then shouldRemove = true break end @@ -634,15 +635,23 @@ function World.observer(world: World, ...) end local queryOutput = {} + local length = 0 + local row = change.offset local archetype = change.archetype local columns = archetype.columns local archetypeRecords = archetype.records for _, id in componentIds do - table.insert(queryOutput, columns[archetypeRecords[id]][row]) + local value = columns[archetypeRecords[id]][row] + if value == nil then + continue + end + + length += 1 + queryOutput[length] = value end - return archetype.entities[row], unpack(queryOutput, 1, #queryOutput) + return archetype.entities[row], unpack(queryOutput, 1, length) end end; }