arkayenro / arkinventory

A World of Warcraft Inventory mod for Retail, Burning Crusade, and Classic
102 stars 14 forks source link

[BUG] Need protection from 'heavy' functionality during Dragonriding, etc. #1813

Closed ImUnicke closed 7 months ago

ImUnicke commented 11 months ago

What version number you are using? v31016 [Dragonflight], v31018 [Dragonflight]

What game client are you playing? Retail, Wrath, Classic / Live, PTR, Beta Retail

What language is the game client set to? English

Describe the bug Consistently when starting every Dragonriding race, the game lags for 500ms after about 2 seconds.

Trying to narrow the cause i used AddonUsage to track the addon which caused the issue, pointing to ArkInventory using 50% CPU during my capture.

Then enabled Debugging in AI to see 'what' it was doing...

** Start Dragonriding Race**
[01:31:02.984102]  EVENT: { [ACTIONBAR_UPDATE_USABLE]=1 }
[01:31:05.195324]  CURRENCY: Start Scan @ 1692257465
[01:31:05.643429]  CURRENCY: End Scan @ 1692257466 [67] [757] [false]
[01:31:05.908602]  EVENT: { [ACTIONBAR_UPDATE_USABLE]=1 }

To Reproduce Start any Dragonriding race and wait

Additional context Think some sort of protection against doing 'heavy' functionality (like lagging the game for a half second) could be very appreciated while doing time-intensive activities in WoW. Especially if this can happen during combat as well (not tested).

hollo6 commented 10 months ago

This is happening to me too. So frustrating to keep missing gold times because the game freezes for a second at the start of every race. I've tried to get debug output but it won't even print anything for me whatsoever, not even if this is the only enabled addon.

chodyo commented 8 months ago

Same problem here, I suspect it has to do with receiving the Bronze Timepiece to the inventory at the beginning of the race.

ImUnicke commented 8 months ago

@arkayenro I made some local adjustments to this which greatly reduce the issue due to performance improvements. (Obviously implementation may not be to the standards of AI design, but the key is to do a name-key table lookup if possible to avoid the iteration call)

Inside ArkInventoryCollectionCurrency.lua:

Add a namecache table to the collection definition

    list = { }, -- [index] = { } - currencies and headers from the blizard frame
    cache = { }, -- [id] = { } - all currencies
    namecache = { }, -- [name] = { } - all currencies

Change GetByName to do a name table lookup if possible to avoid needlessly doing a sorted-pairs-iteration every single time

function ArkInventory.Collection.Currency.GetByName( name )
    if type( name ) == "string" and name ~= "" then
        local obj = collection.namecache[name]
        if obj then
            return obj.id, obj
        end
        for _, obj in ArkInventory.Collection.Currency.Iterate( ) do
            if obj.name == name then
                collection.namecache[name] = obj
                return obj.id, obj
            end
        end
    end
end

In ScanBase add assignment of the namecache lookup table when finding a currency info

local function ScanBase( id )
...

    local cache = collection.cache
    local namecache = collection.namecache

...

                cache[id].link = ArkInventory.CrossClient.GetCurrencyLink( id, 0 )

                namecache[info.name] = info

                collection.numTotal = collection.numTotal + 1

...

On my personal testing, this drops the currency scan from a game-breaking ~0.5+ sec to roughly ~0.1 sec... would prefer not having a currency scan event fired while dragonriding in the first place, but this is a huge help in the meantime.

[18:17:58.277001]  CURRENCY: Start Scan @ 1698797878
[18:17:58.378593]  CURRENCY: End Scan @ 1698797878 [50] [883] [false]
arkayenro commented 8 months ago

its close enough. will be in the next alpha.

i can postpone currency scans while mounted if its still a problem for the races

hollo6 commented 8 months ago

The stutter at the start of a race is still noticeable but not nearly as awful as it was before. Doing something with currency/item scan while mounted would be a good idea for other use cases too, like when you fly through a dreamsurge cluster to collect Dreamsurge Coalescence and crests/fragments.

arkayenro commented 8 months ago

try alpha 2, it shouldnt scan currencies at all white mounted

hollo6 commented 8 months ago

Feels all good to me now! Thanks!

ImUnicke commented 8 months ago

3.10.18-alpha-2 does not trigger the currency scan at all during a Dragonriding race, confirmed by monitoring Debug output window while flying :)

Thanks!

Will you close this issue when pushing the stable branch release? Or you want me to close it ahead of time?

arkayenro commented 7 months ago

fixed in 3.10.19