performance: sort speed improvement

This commit is contained in:
Salikh Gurgenidze
2026-01-24 00:43:13 +04:00
parent 75e4d83fc0
commit e4e6e31072
+15 -18
View File
@@ -9,8 +9,9 @@ addon.Modules.SortEngine = SortEngine
-- Flag to track if sorting is currently in progress -- Flag to track if sorting is currently in progress
SortEngine.sortingInProgress = false SortEngine.sortingInProgress = false
-- Performance: Max items to move per cycle (like Baganator's 5-item limit) -- Performance: Max items to move per cycle
local MAX_MOVES_PER_CYCLE = 5 -- Baganator uses 5 for manual transfers, but sorting needs more for smooth operation
local MAX_MOVES_PER_CYCLE = 20
-- Transfer status constants (like Baganator's SortStatus) -- Transfer status constants (like Baganator's SortStatus)
local TransferStatus = { local TransferStatus = {
@@ -1013,16 +1014,11 @@ end
local function ApplySort(bagIDs, items, targetPositions) local function ApplySort(bagIDs, items, targetPositions)
ClearCursor() ClearCursor()
-- Check if events are pending (like Baganator's IsBagEventPending) -- Clear any pending event flags before sorting
-- If so, wait for them to complete before moving more items -- (Event pending check is for manual transfers, not sorting)
if addon.Modules.BagScanner:IsEventPending() or addon.Modules.BagScanner:ClearEventPending()
(addon.Modules.BankScanner:IsBankOpen() and addon.Modules.BankScanner:IsEventPending()) then if addon.Modules.BankScanner:IsBankOpen() then
-- Clear pending flags and return 0 - will retry on next pass addon.Modules.BankScanner:ClearEventPending()
addon.Modules.BagScanner:ClearEventPending()
if addon.Modules.BankScanner:IsBankOpen() then
addon.Modules.BankScanner:ClearEventPending()
end
return 0
end end
local moveToEmpty = {} local moveToEmpty = {}
@@ -1659,7 +1655,7 @@ function SortEngine:ExecuteSort(sortFunction, analyzeFunction, updateFrame, sort
local frame = CreateFrame("Frame") local frame = CreateFrame("Frame")
local startTime = GetTime() local startTime = GetTime()
frame:SetScript("OnUpdate", function() frame:SetScript("OnUpdate", function()
if GetTime() - startTime >= 0.7 then if GetTime() - startTime >= 0.3 then
frame:SetScript("OnUpdate", nil) frame:SetScript("OnUpdate", nil)
SortEngine.sortingInProgress = false SortEngine.sortingInProgress = false
SortEngine:UpdateSortButtonState(false) SortEngine:UpdateSortButtonState(false)
@@ -1675,7 +1671,7 @@ function SortEngine:ExecuteSort(sortFunction, analyzeFunction, updateFrame, sort
local frame = CreateFrame("Frame") local frame = CreateFrame("Frame")
local startTime = GetTime() local startTime = GetTime()
frame:SetScript("OnUpdate", function() frame:SetScript("OnUpdate", function()
if GetTime() - startTime >= 0.7 then if GetTime() - startTime >= 0.3 then
frame:SetScript("OnUpdate", nil) frame:SetScript("OnUpdate", nil)
SortEngine.sortingInProgress = false SortEngine.sortingInProgress = false
SortEngine:UpdateSortButtonState(false) SortEngine:UpdateSortButtonState(false)
@@ -1698,7 +1694,7 @@ function SortEngine:ExecuteSort(sortFunction, analyzeFunction, updateFrame, sort
local frame = CreateFrame("Frame") local frame = CreateFrame("Frame")
local startTime = GetTime() local startTime = GetTime()
frame:SetScript("OnUpdate", function() frame:SetScript("OnUpdate", function()
if GetTime() - startTime >= 0.7 then if GetTime() - startTime >= 0.3 then
frame:SetScript("OnUpdate", nil) frame:SetScript("OnUpdate", nil)
SortEngine.sortingInProgress = false SortEngine.sortingInProgress = false
SortEngine:UpdateSortButtonState(false) SortEngine:UpdateSortButtonState(false)
@@ -1713,9 +1709,10 @@ function SortEngine:ExecuteSort(sortFunction, analyzeFunction, updateFrame, sort
addon:DebugSort("%s Pass %d: %d moves, %d/%d items remaining (%.1f%%)", addon:DebugSort("%s Pass %d: %d moves, %d/%d items remaining (%.1f%%)",
sortType, passCount, moveCount, currentAnalysis.itemsOutOfPlace, currentAnalysis.totalItems, remainingRatio * 100) sortType, passCount, moveCount, currentAnalysis.itemsOutOfPlace, currentAnalysis.totalItems, remainingRatio * 100)
-- PROGRESSIVE DELAY: Calculate delay based on remaining complexity -- PROGRESSIVE DELAY: Short delay to let server process moves
local baseDelay = 0.9 -- Reduced from 0.9-3.4s to 0.2-0.5s for smoother sorting
local complexityDelay = math.min(currentAnalysis.itemsOutOfPlace * 0.06, 2.5) -- max 2.5 seconds local baseDelay = 0.2
local complexityDelay = math.min(currentAnalysis.itemsOutOfPlace * 0.01, 0.3) -- max 0.3 seconds
local totalDelay = baseDelay + complexityDelay local totalDelay = baseDelay + complexityDelay
addon:DebugSort("Waiting %.1f seconds before next pass...", totalDelay) addon:DebugSort("Waiting %.1f seconds before next pass...", totalDelay)