WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Reducing CPU usage of my addons? (https://www.wowinterface.com/forums/showthread.php?t=20888)

Zasurus 03-08-09 01:09 PM

Reducing CPU usage of my addons?
 
Hi all,
I have made a few small addons and they have been fine but now I am looking at making a slightly bigger addon but this has caused me trouble because although I can make the addon do what I want I can't work out a way to stop the addon taking up 50% CPU for 1/2 sec every time it does a check...

I have searched on the forums but can't find anything even close... I would also like to change a few other addons that do the same as I the map open as a kinda minimap all the time and a few addons don't expect this so blip 30-80% CPU every now and then when they do there checks. This causes the game to stop for this fraction of a second... anoying as ppl jump and arn't where they where when you clicked! :-|

Please help! LOL

Zas

Fuzzywuzzy 03-08-09 01:52 PM

I'm not a coder myself, but i'm pretty sure they (coders) would like to see the code before being able to say anything about what could be causing this.

You could also go ask at wowace.com forums in the developers section.

Shirik 03-08-09 03:57 PM

Moved to the appropriate section.

Also, there is no way we could be able to answer this without your code. You're certainly doing something wrong, but without your code we wouldn't be able to tell what it is.

Mera 03-08-09 04:04 PM

to note Zasurus if you rely on the % on my mod broker_cpu or performancefu it does not mean it takes 50% of the cpu this is a percentage of the growth globally so you can compare how performs the growth between X and Y mods, nor if the growth of Z mod that could be yours you know usually takes 0,15% and that time for the same thing it takes 15% then you could sort out some coding errors that way, nor benchmarking etc but that is not really a percent of your cpu used because there is no ways to know that, the wow api for cpu only returns the time the mod worked, and for memory the amount actually used, that % value is much like a speedmeter you could have in a car, nice to know how many meter you do but at which speed too.

But globally a growth of 50% isnt that a big deal if for exemple this is about opening an option panel etc but if thats in a frequently used function like a loop that could be a problem

But I will update the description of my mod to make it more intructive on that subject, I agree the % value could be badly interpreted

Zasurus 03-08-09 04:05 PM

Quote:

Originally Posted by Fuzzywuzzy (Post 119348)
I'm not a coder myself, but i'm pretty sure they (coders) would like to see the code before being able to say anything about what could be causing this.

You could also go ask at wowace.com forums in the developers section.

While normally I would agree in this case I am not looking for a way to fix broken code I am looking for a way of slowing the execution of code down or reducing its priority so it would be code independent (hopefully! ;-))

Zas

Zasurus 03-08-09 04:08 PM

Quote:

Originally Posted by Mera (Post 119367)
to note Zasurus if you rely on the % on my mod broker_cpu or performancefu it does not mean it takes 50% of the cpu this is a percentage of the growth globally so you can compare how performs the growth between X and Y mods, nor if the growth of Z mod that could be yours you know usually takes 0,15% and that time for the same thing it takes 15% then you could sort out some coding errors that way, nor benchmarking etc but that is not really a percent of your cpu used because there is no ways to know that, the wow api for cpu only returns the time the mod worked, and for memory the amount actually used, that % value is much like a speedmeter you could have in a car, nice to know how many meter you do but at which speed too.

OK I see. Well I guess thats not that bad as I expect it to jump every few seconds then as it won't do anything for ages then get trigured and work for a sec then wait...

Torhal 03-08-09 04:47 PM

It may not be code-independant, depending on what you're doing in your code. If, for example, you're calling a function to get a value that never changes for every iteration in a loop - that could be optimized by assigning the returned value to a local variable exactly once and using it in the iterations.

If you're asking how to delay execution for 0.05 seconds, that depends on what you're doing - is delaying really what you want to do, or would an optimization or two remove the CPU spikes and allow the code to otherwise run as-is?

kneeki 03-11-09 08:21 AM

It would probably be best if you linked us a pasty.net of your code, so we can see what's going on. =)

Vyper 03-11-09 09:58 AM

Quote:

Originally Posted by Zasurus (Post 119368)
While normally I would agree in this case I am not looking for a way to fix broken code I am looking for a way of slowing the execution of code down or reducing its priority so it would be code independent (hopefully! ;-))

Zas

You cannot do that. Addons are not run in separate threads, nor are they interleaved. If say, we have addon A and addon B, and both do something OnEvent. When OnEvent occurs, first A gets the CPU and runs until it gives it up (returns). Then B gets the CPU. Then WoW draws the next frame. There's no parallelism there to screw with, so you can't just set the priority down. Some high CPU addons (such as QuestHelper) implement CPU usage controls with Co-routines (which are NOT parallel, read the Lua doc for details), but for most that shouldn't be necessary. Your best bet is examining your code and trying to figure out whats causing it.

kneeki 03-11-09 03:07 PM

You could 'slow down' code in a way...

Use OnUpdate(elapsed) and have it run your function at your discretion. Look into making a Clock type addon to see how it's done to update once every second (for example)


All times are GMT -6. The time now is 02:31 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI