Thread Tools Display Modes
03-08-09, 01:09 PM   #1
Zasurus
A Cyclonian
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 42
Question 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
  Reply With Quote
03-08-09, 01:52 PM   #2
Fuzzywuzzy
A Black Drake
 
Fuzzywuzzy's Avatar
Join Date: Oct 2007
Posts: 84
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.
  Reply With Quote
03-08-09, 03:57 PM   #3
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
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.
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
03-08-09, 04:04 PM   #4
Mera
Retired of WoW, In ESO :)
 
Mera's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 331
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
__________________
If you need to reach me I'm in ESO, @class101 or "Fathis Ules i"
addons: SpamBayes, BrokerCPU
projects: ThunderBayes
Mera[xeh]? - La CroisadeEcarlate (wow)

Last edited by Mera : 03-08-09 at 04:13 PM.
  Reply With Quote
03-08-09, 04:05 PM   #5
Zasurus
A Cyclonian
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 42
Originally Posted by Fuzzywuzzy View Post
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
  Reply With Quote
03-08-09, 04:08 PM   #6
Zasurus
A Cyclonian
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 42
Originally Posted by Mera View Post
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...
  Reply With Quote
03-08-09, 04:47 PM   #7
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
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?
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
03-11-09, 08:21 AM   #8
kneeki
A Flamescale Wyrmkin
 
kneeki's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 134
It would probably be best if you linked us a pasty.net of your code, so we can see what's going on. =)
  Reply With Quote
03-11-09, 09:58 AM   #9
Vyper
A Rage Talon Dragon Guard
 
Vyper's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 317
Originally Posted by Zasurus View Post
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.
  Reply With Quote
03-11-09, 03:07 PM   #10
kneeki
A Flamescale Wyrmkin
 
kneeki's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 134
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)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Reducing CPU usage of my addons?

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