Accumulation of Lag
CodingDino opened this issue ยท 15 comments
I've definitely noticed that if I do a lot of things that are not basic checking off of steps, such as reloading the guide, reloading the addon as a whole (via the minimap button), or excessive scrolling via the new scrolling feature, I accumulate more and more lag when I check off steps. This isn't an urgent issue, as I think our typical user won't see the problem much since I don't expect them to be spamming the minimap button or scrolling really at all. However it's quite annoying for guide writers and editors, and is something I'd like to look into or have someone look into.
It's probably due to my horribly noobish code generating extra garbage which accumulates the more it's used. I just don't have enough coding experience to really know what to do to fix it, so if someone with more programming fu wants to check this problem out, I'd be very appreciative.
Jiyambi, is there any reason why you get and return the same script here? That's in the WoWPro_Leveling:LoadGuide() function.
local f = WoWPro.Scrollbar:GetScript("OnValueChanged")
WoWPro.Scrollbar:SetScript("OnValueChanged", function(self, value, ...)
local offset = math.floor(value)
WoWPro:UpdateGuide(offset)
return f(self, value, ...)
end)
Well, I made some changes to it and I think this issue of accumulation of lag is fixed. I opened up a pull request.
Well, the recursiveness in the script above (returning itself) is what causing the growing lag. Commenting out get/return f didnt seem to break anything, so I'll push my changes so you can test it out.
Sorry, I was intending to respond to this and must have gotten side tracked. The scrollbar stuff (the offset) was copy and pasted around a bit while I was setting up, so I think the extra return is from that. Woops! Thanks very much for catching that, as always!
I think I know the cause of part of this now, but not how to fix it.
When we load a guide (anytime WoWPro:LoadGuide() is called), we reinitialize a large set of empty tables. Every time this is done, garbage is created. We can't just reuse these tables because our guides are different sizes. So I'm not really sure how to avoid this.
This explains the cause of accumulated lag when loading and reloading guides, but not lag caused by scrolling. Still need to look into that.
As you know, I'm no Lua expert (I like to manage my own resources in C/C++ ;) ), but have you tried to force a garbage collecting inside and at the end of WoWPro:LoadGuide() ? Try to use this lua function: collectgarbage("collect")
It could cause more processing time each time LoadGuide() is called, but maybe it will help with the increasing garbage.
Will do! Since LoadGuide() is not called often, I think that would be an acceptable trade off. I probably won't get to experiment until tomorrow or later this week, though.
So try to call the garbage collector anywhere after you declare the new tables, or I don't think the old tables will be considered garbage before that. Lua is too complicated. :p
Alright. Since I haven't ever experienced one of the crashes (I reload so often things don't really have time to accumulate usually) we'll just have to implement the garbage collector and see if that helps fix this.
I just added in the garbage collector and it doesn't seem to have made a difference :( Resetting the guide multiple times takes longer each time, and all UpdateGuide() calls take longer and longer the more times the guide is reset. I'm assuming this is still due to something accumulated during the LoadGuide() function.
EDIT: Same effect from clicking many different guides in the Guide List.
Lag is definitely still happening after using the scrolling function excessively, as well. Bah.