Thread Tools Display Modes
06-11-10, 06:45 AM   #1
dr_AllCOM3
A Cyclonian
 
dr_AllCOM3's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 40
COMBAT_LOG_EVENT_UNFILTERED improvement help

I wonder if that code can be improved. It takes up quite some cpu time. Nothing extremely bad, but COMBAT_LOG_EVENT_UNFILTERED is called very often and mostly at bad times.
Thanks in advance for looking through it.


Code:
function addon:COMBAT_LOG_EVENT_UNFILTERED( event, ... )
    --timestamp, eventType, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags
	local _, event  = ...
    
    if addon[event] then
		addon[event]( self, ... )
	end
end

function addon:SPELL_AURA_APPLIED( ... )
    --timestamp, eventType, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags
    local timestamp, eventType, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags = select( 1, ... )
    
    local spellId, spellName, spellSchool, auraType, amount  = select( 9, ... )
    
    if playerGUID==dstGUID or playerTargetGUID==dstGUID then return end -- No auras from player wanted.
    
    local fromPlayer = srcGUID==playerGUID and 1
    
    if auraType=="DEBUFF" then
        auraType = "HARMFUL"
    elseif auraType=="BUFF" then
        auraType = "HELPFUL"
    end
    
    local priority = checkFilter( strlower( spellName ), fromPlayer, auraType )
    
    if priority then
        if global.spellList[spellId] then
            local time = GetTime()
            
            table[dstGUID] = table[dstGUID] or {}
            
            tinsert( guidBuffs[dstGUID], { stuff = stuff, priority = priority, and so on } )
        else
            -- Almost the same
        end
    end
    
    update( dstGUID )
end

local function checkFilter( spellName, fromPlayer, auraType ) -- Filter aura
    local list
    if auraType=="HELPFUL" then
        list = db.buffFilter.buffs
    elseif auraType=="HARMFUL" then
        list = db.buffFilter.debuffs
    else
        return nil
    end
    
    if list.never[spellName] then
        return nil
    elseif fromPlayer and list.my[spellName] then
        return list.my[spellName]
    elseif list.any[spellName] then
        return list.any[spellName]
    elseif fromPlayer and list.allMy then
        return 1
    elseif list.allAny then
        return 1
    else
        return nil
    end
end
There are more like SPELL_AURA_REMOVED and the other SPELL_AURA changes on units, but they're far smaller and have no further checks or filtering.
  Reply With Quote
06-11-10, 07:02 AM   #2
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
Originally Posted by dr_AllCOM3 View Post
Code:
            tinsert( guidBuffs[dstGUID], { stuff = stuff, priority = priority, and so
This could get expensive depending on how often the table values are being added & removed. While it's not likely that you'll generate enough tables to have an effect by themselves, if the additional tables don't have a reference (i.e. you removed the value when it was no longer being used) they're going to be garbage collected.

You shouldn't be using varargs in your subevents. The number of arguments returned will always be the same. You'll save a tiny bit of time by not having to use the select function.

You're using strlower to check for keys in all of your list tables. It's not going to make or break the function speed, but you shouldn't do it unless it improves functionality or readability.

I personally don't see any other blatant problems though. I also can't really visualize what you're attempting to do to see if there's an alternative method.

Last edited by Waverian : 06-11-10 at 07:08 AM.
  Reply With Quote
06-11-10, 07:18 AM   #3
dr_AllCOM3
A Cyclonian
 
dr_AllCOM3's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 40
The tinsert isn't used very often, that's what the filtering is for .
Is varargs the ... ? I'll try that, thanks.
strlower is just for convenience. I could remove that and just tell the user to watch out for proper cases.

I'm trying to improve my COMBAT_LOG function, since it uses the vast majority of my addon's CPU time. Maybe there are some tricks or common practices to handle the COMBAT_LOG.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » COMBAT_LOG_EVENT_UNFILTERED improvement help

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off