07-10-19, 08:03 AM | #1 |
Minimap Coordinates Memory Usage Optimization
The following code is used within my personal minimap addon. The code will cause a constant 3 kb/second gain of memory until garbage collection is run, and goes back down quite low. Is there a way to run this and not have constant garbage being built?
Lua Code:
|
|
07-10-19, 08:48 AM | #2 |
Because the C_Map.GetPlayerMapPosition always create a new table as the result, so the memory usage will constantly increasing.
Here is a solution from other author: Lua Code:
|
|
07-10-19, 09:13 AM | #3 |
Absolutely brilliant, thank you so much!
|
|
07-10-19, 10:41 AM | #4 |
May have gone a little overboard but this should increase performance significantly.
Edit: Decided to take out the comments after fixing it up; I'm clearly bad at explaining myself. Lua Code:
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison Last edited by jeruku : 07-10-19 at 08:59 PM. Reason: Okay, totally fixed... hopefully. |
|
07-10-19, 02:06 PM | #5 | ||||
__________________
WoWInterface AddOns
Last edited by SDPhantom : 07-10-19 at 02:32 PM. |
|||||
07-10-19, 02:36 PM | #6 |
I've been coding my UI casually for ~ 6 years. Turns out I'm still garbage at it compared to you all. It's incredible how absolutely complex you can get to squeeze every inch out of CPU/RAM if you sit down and really go for it.
|
|
07-10-19, 03:10 PM | #7 | |
It's the nature of being in a community. You can pick up things from others you might have never come across on your own.
__________________
WoWInterface AddOns
|
||
07-10-19, 08:56 PM | #8 | ||
And to my knowledge a table lookup inside a function from a passed variable(self or vararg) is faster than calling a variable from outside of scope. In the cases where you're dealing with a single frame it takes up the same amount of space and is only slightly faster; if you were using OnUpdate on something like hundreds/thousands of frames it would be a trade off between CPU vs RAM depending on the number/type of things added to, or used from, the table. Sadly I'm used to doing it this way and it's certainly a bad habit.
Thanks for pointing that out, that was my bad and I have no excuse. I have absolutely no idea why I thought that would work. I corrected my post and will correct it further.
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison |
|||
07-11-19, 08:59 AM | #9 |
I modified it ever so slightly to this:
Lua Code:
I reworked the OnEvent handler to unregister and register the movement and zone changes if the player is in an instance so it won't be running in there where there are no coordinates. Last edited by Terenna : 07-11-19 at 09:13 AM. |
|
07-11-19, 11:46 AM | #10 |
I use AceTimer-3.0 for updating my coords frame:
Lua Code:
|
|
07-11-19, 04:42 PM | #11 | |
CPU will always be WoW's bottleneck. Do not be afraid to cache as much data as possible instead of querying the API. The less you do each frame, especially in combat, the better.
__________________
|
||
07-12-19, 10:40 AM | #12 | |
Lua Code:
The function LongLoop will be processed in a coroutine, and the Continue method will yield it if there is no more time for tasks in the same frame and resume it in the next frame if there is enough time. This is how the script runs in my old laptop(i5-3230M), I changed a setting to keep the fps to 60, so for one frame the loop will be processed for 2k6-4k times, with the task schedule system I can smooth all my addons to keep the high fps(for my old hardware). test.jpg Besides the Continue, there are many others like Wait to wait for several system events, so for me, I can re-code Terenna's code like : Lua Code:
Although I need more codes(include the framework) to do the same operations, we still can gain better performance through carefully coroutine controls. Last edited by kurapica.igas : 07-12-19 at 10:44 AM. |
||
07-21-19, 06:58 AM | #13 | |
Lua Code:
|
||
WoWInterface » Developer Discussions » Lua/XML Help » Minimap Coordinates Memory Usage Optimization |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|