mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Refactor stress test files to enhance clarity and performance
- Removed unnecessary references to LargeTreeGenerator in multiple stress test files, streamlining the code. - Simplified loop iterations by replacing index variables with underscores for unused values, improving readability. - Updated the diff logic in the reify and diff tests to eliminate unused patch variables, enhancing performance and clarity. - Ensured consistent formatting across stress test files for better maintainability.
This commit is contained in:
parent
d513ab16c0
commit
09a0f95d53
8 changed files with 12 additions and 20 deletions
|
|
@ -7,8 +7,6 @@
|
||||||
return function()
|
return function()
|
||||||
local PatchSet = require(script.Parent.PatchSet)
|
local PatchSet = require(script.Parent.PatchSet)
|
||||||
local InstanceMap = require(script.Parent.InstanceMap)
|
local InstanceMap = require(script.Parent.InstanceMap)
|
||||||
local testUtils = require(script.Parent.testUtils)
|
|
||||||
local PatchGenerator = testUtils.PatchGenerator
|
|
||||||
|
|
||||||
local HttpService = game:GetService("HttpService")
|
local HttpService = game:GetService("HttpService")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ return function()
|
||||||
local PatchSet = require(script.Parent.Parent.PatchSet)
|
local PatchSet = require(script.Parent.Parent.PatchSet)
|
||||||
local testUtils = require(script.Parent.Parent.testUtils)
|
local testUtils = require(script.Parent.Parent.testUtils)
|
||||||
local PatchGenerator = testUtils.PatchGenerator
|
local PatchGenerator = testUtils.PatchGenerator
|
||||||
local LargeTreeGenerator = testUtils.LargeTreeGenerator
|
|
||||||
|
|
||||||
local HttpService = game:GetService("HttpService")
|
local HttpService = game:GetService("HttpService")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ return function()
|
||||||
|
|
||||||
-- Fix up children references
|
-- Fix up children references
|
||||||
for id, virt in pairs(virtualInstances) do
|
for id, virt in pairs(virtualInstances) do
|
||||||
for i, childPlaceholder in ipairs(virt.Children) do
|
for i, _ in ipairs(virt.Children) do
|
||||||
-- Find the actual child ID
|
-- Find the actual child ID
|
||||||
for otherId, otherVirt in pairs(virtualInstances) do
|
for otherId, otherVirt in pairs(virtualInstances) do
|
||||||
if otherVirt.Parent == id then
|
if otherVirt.Parent == id then
|
||||||
|
|
@ -529,7 +529,7 @@ return function()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local ok, patch = diff(instanceMap, virtualInstances, rootId)
|
local ok, _ = diff(instanceMap, virtualInstances, rootId)
|
||||||
|
|
||||||
expect(ok).to.equal(true)
|
expect(ok).to.equal(true)
|
||||||
-- CFrame decoding might not work in test env, but the test structure is valid
|
-- CFrame decoding might not work in test env, but the test structure is valid
|
||||||
|
|
@ -957,7 +957,7 @@ return function()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local ok, patch = diff(instanceMap, virtualInstances, rootId)
|
local ok, _ = diff(instanceMap, virtualInstances, rootId)
|
||||||
|
|
||||||
expect(ok).to.equal(true)
|
expect(ok).to.equal(true)
|
||||||
-- Should be considered equal
|
-- Should be considered equal
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ return function()
|
||||||
local PatchSet = require(script.Parent.Parent.PatchSet)
|
local PatchSet = require(script.Parent.Parent.PatchSet)
|
||||||
local InstanceMap = require(script.Parent.Parent.InstanceMap)
|
local InstanceMap = require(script.Parent.Parent.InstanceMap)
|
||||||
local testUtils = require(script.Parent.Parent.testUtils)
|
local testUtils = require(script.Parent.Parent.testUtils)
|
||||||
local LargeTreeGenerator = testUtils.LargeTreeGenerator
|
|
||||||
|
|
||||||
local HttpService = game:GetService("HttpService")
|
local HttpService = game:GetService("HttpService")
|
||||||
|
|
||||||
|
|
@ -43,11 +42,9 @@ return function()
|
||||||
-- Build virtual instances for 20-level deep tree
|
-- Build virtual instances for 20-level deep tree
|
||||||
local parentId = nil
|
local parentId = nil
|
||||||
local rootId = nil
|
local rootId = nil
|
||||||
local ids = {}
|
|
||||||
|
|
||||||
for i = 1, 20 do
|
for i = 1, 20 do
|
||||||
local id = generateId()
|
local id = generateId()
|
||||||
table.insert(ids, id)
|
|
||||||
|
|
||||||
if rootId == nil then
|
if rootId == nil then
|
||||||
rootId = id
|
rootId = id
|
||||||
|
|
@ -271,7 +268,7 @@ return function()
|
||||||
local children = {}
|
local children = {}
|
||||||
local invalidIds = {}
|
local invalidIds = {}
|
||||||
|
|
||||||
for i = 1, 5 do
|
for _ = 1, 5 do
|
||||||
local childId = generateId()
|
local childId = generateId()
|
||||||
table.insert(children, childId)
|
table.insert(children, childId)
|
||||||
table.insert(invalidIds, childId)
|
table.insert(invalidIds, childId)
|
||||||
|
|
@ -519,7 +516,7 @@ return function()
|
||||||
describe("performance", function()
|
describe("performance", function()
|
||||||
it("should create 200+ instances in reasonable time", function()
|
it("should create 200+ instances in reasonable time", function()
|
||||||
local instanceMap = InstanceMap.new()
|
local instanceMap = InstanceMap.new()
|
||||||
local treeData = LargeTreeGenerator.createVirtualTree({
|
local treeData = testUtils.LargeTreeGenerator.createVirtualTree({
|
||||||
depth = 3,
|
depth = 3,
|
||||||
width = 6, -- 6^3 = 216 instances
|
width = 6, -- 6^3 = 216 instances
|
||||||
instanceType = "Folder",
|
instanceType = "Folder",
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ return function()
|
||||||
local applyPatch = require(script.Parent.Parent.Reconciler.applyPatch)
|
local applyPatch = require(script.Parent.Parent.Reconciler.applyPatch)
|
||||||
local diff = require(script.Parent.Parent.Reconciler.diff)
|
local diff = require(script.Parent.Parent.Reconciler.diff)
|
||||||
local testUtils = require(script.Parent.Parent.testUtils)
|
local testUtils = require(script.Parent.Parent.testUtils)
|
||||||
local LargeTreeGenerator = testUtils.LargeTreeGenerator
|
|
||||||
local PatchGenerator = testUtils.PatchGenerator
|
local PatchGenerator = testUtils.PatchGenerator
|
||||||
|
|
||||||
local HttpService = game:GetService("HttpService")
|
local HttpService = game:GetService("HttpService")
|
||||||
|
|
@ -47,7 +46,7 @@ return function()
|
||||||
local rootId = generateId()
|
local rootId = generateId()
|
||||||
instanceMap:insert(rootId, root)
|
instanceMap:insert(rootId, root)
|
||||||
|
|
||||||
for i = 1, 50 do
|
for _ = 1, 50 do
|
||||||
-- Add
|
-- Add
|
||||||
local addPatch = PatchGenerator.createAdditionsPatch({
|
local addPatch = PatchGenerator.createAdditionsPatch({
|
||||||
count = 5,
|
count = 5,
|
||||||
|
|
@ -86,7 +85,7 @@ return function()
|
||||||
|
|
||||||
local allIds = {}
|
local allIds = {}
|
||||||
|
|
||||||
for i = 1, 30 do
|
for _ = 1, 30 do
|
||||||
-- Add some
|
-- Add some
|
||||||
local addPatch = PatchGenerator.createAdditionsPatch({
|
local addPatch = PatchGenerator.createAdditionsPatch({
|
||||||
count = 3,
|
count = 3,
|
||||||
|
|
@ -101,7 +100,7 @@ return function()
|
||||||
-- Remove some (if we have any)
|
-- Remove some (if we have any)
|
||||||
if #allIds > 5 then
|
if #allIds > 5 then
|
||||||
local toRemove = {}
|
local toRemove = {}
|
||||||
for j = 1, 2 do
|
for _ = 1, 2 do
|
||||||
if #allIds > 0 then
|
if #allIds > 0 then
|
||||||
table.insert(toRemove, table.remove(allIds, 1))
|
table.insert(toRemove, table.remove(allIds, 1))
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ return function()
|
||||||
instanceMap:insert(rootId, root)
|
instanceMap:insert(rootId, root)
|
||||||
|
|
||||||
-- Apply 10 consecutive patches
|
-- Apply 10 consecutive patches
|
||||||
for i = 1, 10 do
|
for _ = 1, 10 do
|
||||||
local patch = PatchGenerator.createAdditionsPatch({
|
local patch = PatchGenerator.createAdditionsPatch({
|
||||||
count = 5,
|
count = 5,
|
||||||
parentId = rootId,
|
parentId = rootId,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ return function()
|
||||||
local InstanceMap = require(script.Parent.Parent.InstanceMap)
|
local InstanceMap = require(script.Parent.Parent.InstanceMap)
|
||||||
local PatchSet = require(script.Parent.Parent.PatchSet)
|
local PatchSet = require(script.Parent.Parent.PatchSet)
|
||||||
local applyPatch = require(script.Parent.Parent.Reconciler.applyPatch)
|
local applyPatch = require(script.Parent.Parent.Reconciler.applyPatch)
|
||||||
local diff = require(script.Parent.Parent.Reconciler.diff)
|
|
||||||
local encodeInstance = require(script.Parent.Parent.ChangeBatcher.encodeInstance)
|
local encodeInstance = require(script.Parent.Parent.ChangeBatcher.encodeInstance)
|
||||||
local testUtils = require(script.Parent.Parent.testUtils)
|
local testUtils = require(script.Parent.Parent.testUtils)
|
||||||
local PatchGenerator = testUtils.PatchGenerator
|
local PatchGenerator = testUtils.PatchGenerator
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ function LargeTreeGenerator.createInstanceTree(options)
|
||||||
local withDuplicates = options.withDuplicates or false
|
local withDuplicates = options.withDuplicates or false
|
||||||
local duplicateCount = options.duplicateCount or 2
|
local duplicateCount = options.duplicateCount or 2
|
||||||
|
|
||||||
local function createInstance(name, level)
|
local function createInstance(name, _level)
|
||||||
local className = instanceType
|
local className = instanceType
|
||||||
if instanceType == "mixed" then
|
if instanceType == "mixed" then
|
||||||
className = LargeTreeGenerator.randomInstanceType()
|
className = LargeTreeGenerator.randomInstanceType()
|
||||||
|
|
@ -103,7 +103,7 @@ function LargeTreeGenerator.createInstanceTree(options)
|
||||||
|
|
||||||
-- Optionally create duplicates
|
-- Optionally create duplicates
|
||||||
if withDuplicates and currentDepth <= 2 then -- Only add duplicates at top levels
|
if withDuplicates and currentDepth <= 2 then -- Only add duplicates at top levels
|
||||||
for i = 1, duplicateCount do
|
for _ = 1, duplicateCount do
|
||||||
local duplicateName = prefix .. "_1" -- Same name as first child
|
local duplicateName = prefix .. "_1" -- Same name as first child
|
||||||
local duplicate = createInstance(duplicateName, currentDepth)
|
local duplicate = createInstance(duplicateName, currentDepth)
|
||||||
duplicate.Parent = parent
|
duplicate.Parent = parent
|
||||||
|
|
@ -240,7 +240,7 @@ end
|
||||||
]]
|
]]
|
||||||
function LargeTreeGenerator.countInstances(root)
|
function LargeTreeGenerator.countInstances(root)
|
||||||
local count = 1 -- Count the root
|
local count = 1 -- Count the root
|
||||||
for _, child in ipairs(root:GetDescendants()) do
|
for _ in ipairs(root:GetDescendants()) do
|
||||||
count = count + 1
|
count = count + 1
|
||||||
end
|
end
|
||||||
return count
|
return count
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue