From 09a0f95d5317d8b907d5243dd79d52c872d63d07 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 1 Feb 2026 22:14:59 -0600 Subject: [PATCH] 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. --- plugin/src/PatchSet.stress.spec.lua | 2 -- plugin/src/Reconciler/applyPatch.stress.spec.lua | 1 - plugin/src/Reconciler/diff.stress.spec.lua | 6 +++--- plugin/src/Reconciler/reify.stress.spec.lua | 7 ++----- plugin/src/chaos/stressPatterns.spec.lua | 7 +++---- plugin/src/integration/syncflow.spec.lua | 2 +- plugin/src/integration/twoWaySync.spec.lua | 1 - plugin/src/testUtils/LargeTreeGenerator.lua | 6 +++--- 8 files changed, 12 insertions(+), 20 deletions(-) diff --git a/plugin/src/PatchSet.stress.spec.lua b/plugin/src/PatchSet.stress.spec.lua index 3611482e..bb4ad3a4 100644 --- a/plugin/src/PatchSet.stress.spec.lua +++ b/plugin/src/PatchSet.stress.spec.lua @@ -7,8 +7,6 @@ return function() local PatchSet = require(script.Parent.PatchSet) local InstanceMap = require(script.Parent.InstanceMap) - local testUtils = require(script.Parent.testUtils) - local PatchGenerator = testUtils.PatchGenerator local HttpService = game:GetService("HttpService") diff --git a/plugin/src/Reconciler/applyPatch.stress.spec.lua b/plugin/src/Reconciler/applyPatch.stress.spec.lua index a23a45d6..27492c50 100644 --- a/plugin/src/Reconciler/applyPatch.stress.spec.lua +++ b/plugin/src/Reconciler/applyPatch.stress.spec.lua @@ -11,7 +11,6 @@ return function() local PatchSet = require(script.Parent.Parent.PatchSet) local testUtils = require(script.Parent.Parent.testUtils) local PatchGenerator = testUtils.PatchGenerator - local LargeTreeGenerator = testUtils.LargeTreeGenerator local HttpService = game:GetService("HttpService") diff --git a/plugin/src/Reconciler/diff.stress.spec.lua b/plugin/src/Reconciler/diff.stress.spec.lua index e24258e5..14b0468d 100644 --- a/plugin/src/Reconciler/diff.stress.spec.lua +++ b/plugin/src/Reconciler/diff.stress.spec.lua @@ -122,7 +122,7 @@ return function() -- Fix up children references 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 for otherId, otherVirt in pairs(virtualInstances) do 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) -- 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) -- Should be considered equal diff --git a/plugin/src/Reconciler/reify.stress.spec.lua b/plugin/src/Reconciler/reify.stress.spec.lua index 2cd592b7..83e407f7 100644 --- a/plugin/src/Reconciler/reify.stress.spec.lua +++ b/plugin/src/Reconciler/reify.stress.spec.lua @@ -11,7 +11,6 @@ return function() local PatchSet = require(script.Parent.Parent.PatchSet) local InstanceMap = require(script.Parent.Parent.InstanceMap) local testUtils = require(script.Parent.Parent.testUtils) - local LargeTreeGenerator = testUtils.LargeTreeGenerator local HttpService = game:GetService("HttpService") @@ -43,11 +42,9 @@ return function() -- Build virtual instances for 20-level deep tree local parentId = nil local rootId = nil - local ids = {} for i = 1, 20 do local id = generateId() - table.insert(ids, id) if rootId == nil then rootId = id @@ -271,7 +268,7 @@ return function() local children = {} local invalidIds = {} - for i = 1, 5 do + for _ = 1, 5 do local childId = generateId() table.insert(children, childId) table.insert(invalidIds, childId) @@ -519,7 +516,7 @@ return function() describe("performance", function() it("should create 200+ instances in reasonable time", function() local instanceMap = InstanceMap.new() - local treeData = LargeTreeGenerator.createVirtualTree({ + local treeData = testUtils.LargeTreeGenerator.createVirtualTree({ depth = 3, width = 6, -- 6^3 = 216 instances instanceType = "Folder", diff --git a/plugin/src/chaos/stressPatterns.spec.lua b/plugin/src/chaos/stressPatterns.spec.lua index a1d99a25..5f60cd61 100644 --- a/plugin/src/chaos/stressPatterns.spec.lua +++ b/plugin/src/chaos/stressPatterns.spec.lua @@ -11,7 +11,6 @@ return function() local applyPatch = require(script.Parent.Parent.Reconciler.applyPatch) local diff = require(script.Parent.Parent.Reconciler.diff) local testUtils = require(script.Parent.Parent.testUtils) - local LargeTreeGenerator = testUtils.LargeTreeGenerator local PatchGenerator = testUtils.PatchGenerator local HttpService = game:GetService("HttpService") @@ -47,7 +46,7 @@ return function() local rootId = generateId() instanceMap:insert(rootId, root) - for i = 1, 50 do + for _ = 1, 50 do -- Add local addPatch = PatchGenerator.createAdditionsPatch({ count = 5, @@ -86,7 +85,7 @@ return function() local allIds = {} - for i = 1, 30 do + for _ = 1, 30 do -- Add some local addPatch = PatchGenerator.createAdditionsPatch({ count = 3, @@ -101,7 +100,7 @@ return function() -- Remove some (if we have any) if #allIds > 5 then local toRemove = {} - for j = 1, 2 do + for _ = 1, 2 do if #allIds > 0 then table.insert(toRemove, table.remove(allIds, 1)) end diff --git a/plugin/src/integration/syncflow.spec.lua b/plugin/src/integration/syncflow.spec.lua index dbc9a33c..3b210536 100644 --- a/plugin/src/integration/syncflow.spec.lua +++ b/plugin/src/integration/syncflow.spec.lua @@ -185,7 +185,7 @@ return function() instanceMap:insert(rootId, root) -- Apply 10 consecutive patches - for i = 1, 10 do + for _ = 1, 10 do local patch = PatchGenerator.createAdditionsPatch({ count = 5, parentId = rootId, diff --git a/plugin/src/integration/twoWaySync.spec.lua b/plugin/src/integration/twoWaySync.spec.lua index d89e96a4..22926761 100644 --- a/plugin/src/integration/twoWaySync.spec.lua +++ b/plugin/src/integration/twoWaySync.spec.lua @@ -8,7 +8,6 @@ return function() local InstanceMap = require(script.Parent.Parent.InstanceMap) local PatchSet = require(script.Parent.Parent.PatchSet) 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 testUtils = require(script.Parent.Parent.testUtils) local PatchGenerator = testUtils.PatchGenerator diff --git a/plugin/src/testUtils/LargeTreeGenerator.lua b/plugin/src/testUtils/LargeTreeGenerator.lua index 8b38aaff..1b57b1ac 100644 --- a/plugin/src/testUtils/LargeTreeGenerator.lua +++ b/plugin/src/testUtils/LargeTreeGenerator.lua @@ -70,7 +70,7 @@ function LargeTreeGenerator.createInstanceTree(options) local withDuplicates = options.withDuplicates or false local duplicateCount = options.duplicateCount or 2 - local function createInstance(name, level) + local function createInstance(name, _level) local className = instanceType if instanceType == "mixed" then className = LargeTreeGenerator.randomInstanceType() @@ -103,7 +103,7 @@ function LargeTreeGenerator.createInstanceTree(options) -- Optionally create duplicates 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 duplicate = createInstance(duplicateName, currentDepth) duplicate.Parent = parent @@ -240,7 +240,7 @@ end ]] function LargeTreeGenerator.countInstances(root) local count = 1 -- Count the root - for _, child in ipairs(root:GetDescendants()) do + for _ in ipairs(root:GetDescendants()) do count = count + 1 end return count