Official Pawn forums Forum Index
  
slow initialization

 
Post new topic   Reply to topic    Official Pawn forums Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
pherra



Joined: 05 Jul 2010
Posts: 3

PostPosted: Mon Jul 05, 2010 7:05 pm    Post subject: slow initialization Reply with quote

I was looking into slow login times and found Pawn to be the addon that had used the most CPU time when I checked immediately after zoning in. I tracked down most of this time to extracting raw gem data to calculate the best gems for every single scale. I was able to drop the time from >10 seconds to ~130ms by adding a cache for the function PawnGetGemData.

Now my copy looks like

Code:
PawnGetGemDataCache = {}
function PawnGetGemData(GemData)
        local ItemID = GemData[1]

        if PawnGetGemDataCache[ItemID] ~= nil then
          return PawnGetGemDataCache[ItemID]
        end

        local ItemName, ItemLink, ItemRarity, ItemLevel, _, _, _, _, _, ItemTexture = GetItemInfo(ItemID)
        if ItemLink == nil or ItemName == nil then
                -- If the gem doesn't exist in the user's local cache, we'll have to fake up some info for it.
                ItemLink = string.format(PawnLocal.GenericGemLink, ItemID, ItemID)
                ItemName = string.format(PawnLocal.GenericGemName, ItemID)
        end
        local Item = PawnGetEmptyCachedItem(ItemLink, ItemName)
        Item.ID = ItemID
        Item.Rarity = ItemRarity
        Item.Level = ItemLevel
        Item.Texture = ItemTexture
        Item.UnenchantedStats = { }
        if GemData[5] then
                Item.UnenchantedStats[GemData[5]] = GemData[6]
        end
        if GemData[7] then
                Item.UnenchantedStats[GemData[7]] = GemData[8]
        end
        PawnRecalculateItemValuesIfNecessary(Item, true) -- Ignore the user's normalization factor when determining these gem values.

        PawnGetGemDataCache[ItemID] = Item
        return Item
end


The cache will never get big since it is limited to one entry per gem, and as far as I can tell, the output never varies for a particular gem. If the output is supposed to be mutable, then perhaps the data to be returned can be cached and a fresh copy cloned to return.
Back to top
View user's profileSend private message
Vger
Pawn Mod Creator


Joined: 09 Jul 2007
Posts: 120
Location: Azjol-Nerub (US)

PostPosted: Tue Jul 06, 2010 12:35 pm    Post subject: Reply with quote

Thanks for the suggestion—as far as I know there should be no issues with doing that. I've actually done almost exactly this for Pawn 1.3.6, which should be ready shortly, though on my computer it only makes a difference of 1-2 seconds... I'm surprised that it made such a big difference for you! (That 1-2 seconds is still 95% of Pawn's startup time.) There are some other performance enhancements coming in this version that will make almost all aspects of Pawn faster.

Sorry for the slowness!
Back to top
View user's profileSend private messageVisit poster's website
bando



Joined: 09 Jul 2007
Posts: 76
Location: Garona-US

PostPosted: Mon Jul 12, 2010 8:04 am    Post subject: Reply with quote

I've never tried to look this up; how do you measure CPU time for individual mods in-game?
Back to top
View user's profileSend private message
pherra



Joined: 05 Jul 2010
Posts: 3

PostPosted: Mon Jul 12, 2010 8:35 pm    Post subject: Reply with quote

There are tons of addons to monitor addon CPU usage. I happen to use BrokerCPU. To find out which particular functions were expensive, I wrote a little wrapper around GetFunctionCPUUsage() and read the Pawn source to find candidate functions.
Back to top
View user's profileSend private message
Vger
Pawn Mod Creator


Joined: 09 Jul 2007
Posts: 120
Location: Azjol-Nerub (US)

PostPosted: Tue Jul 13, 2010 3:05 pm    Post subject: Reply with quote

Gem-related performance updates and some other improvements are all in the latest version of Pawn, which you can pick up at any of the major mod sites.

Thanks pherra—I didn't actually know that there was a GetFunctionCPUUsage() function. Do you know of any mods that might use it to display info in a usable manner? I'm guessing not since you mention a wrapper function.
Back to top
View user's profileSend private messageVisit poster's website
pherra



Joined: 05 Jul 2010
Posts: 3

PostPosted: Wed Jul 21, 2010 8:22 am    Post subject: Reply with quote

I don't know any, but I didn't look to hard either. I can post the wrapper if you like. I think the whole thing was only about 10 lines.
Back to top
View user's profileSend private message
Vger
Pawn Mod Creator


Joined: 09 Jul 2007
Posts: 120
Location: Azjol-Nerub (US)

PostPosted: Wed Jul 21, 2010 12:09 pm    Post subject: Reply with quote

I'm sure I'll be able to figure it out. Thanks for the bug report. :)
Back to top
View user's profileSend private messageVisit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Official Pawn forums Forum Index -> Bug Reports All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum