Thread Tools Display Modes
04-13-13, 11:10 AM   #21
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Torhal View Post
That would be "polling the combat log" so definitely no
And how about if i have a local copy of select, it's not the same?
  Reply With Quote
04-13-13, 11:29 AM   #22
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
You still incur the computational cost of a function call each time, upvalued or not.
  Reply With Quote
04-13-13, 01:00 PM   #23
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Function calls are more expensive than looking up a variable.

/edit: Now, we're talking 0.000000001 of a second here, but it all adds up, especially when doing it often like in response to CLEU (COMBAT_LOG_EVENT_UNFILTERED)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
04-13-13, 01:36 PM   #24
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Calling a function is pretty much the slowest thing you can do. It's even faster to do three table lookups:

Code:
local color = { 1, 0, 1 }
local r, g, b = color[1], color[2], color[3]
... than to do one function call:

Code:
local color = { 1, 0, 1 }
local r, g, b = unpack(color)
... even if you've upvalued the function.

Since select can be avoided in pretty much every single case, you should avoid it. Do this:

Code:
local _, _, _, _, _, var = GetSomeValues()
print(var)
... instead of this:

Code:
print((select(6, GetSomeValues()))
The former may be "more code" but it's faster, and more readable, and definitely more efficient if you're using other values returned by the same function -- I've seen some addons where the same function is called multiple times in a row, wrapped in different select calls. Huge waste of CPU time.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 04-13-13 at 01:38 PM.
  Reply With Quote
04-14-13, 05:53 AM   #25
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
Calling a function is pretty much the slowest thing you can do.
Yeah, i understand this but when you call the "GetSomeValues()" its 90% a global blizzard function, which means you already calling a function which is limited by your latency and stuff.
  Reply With Quote
04-14-13, 06:52 AM   #26
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
The only things that are limited by your latency are un-cached item information (ala GetItemInfo) and inspect info. I've possibly missed a few others, but the point is that most of the API functions are client-side and needlessly calling functions "because it's cleaner" is also needlessly using CPU which might seem innocent until you realize multiple AddOns are sharing the CPU load and all of this quickly adds up.
__________________
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
04-14-13, 07:41 AM   #27
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Torhal View Post
The only things that are limited by your latency are un-cached item information (ala GetItemInfo) and inspect info. I've possibly missed a few others, but the point is that most of the API functions are client-side and needlessly calling functions "because it's cleaner" is also needlessly using CPU which might seem innocent until you realize multiple AddOns are sharing the CPU load and all of this quickly adds up.
Yes, but i'm pretty sure the combat log is not "just" client sided.
  Reply With Quote
04-14-13, 07:56 AM   #28
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
It's pure client side as far as code is concerned, because as far as addons are concerned "information appears > process information".

I don't think there's any API we can use with regards to the combat log which sends a request to the Blizzard servers for more information. All information is streamed straight to us. Which means there's nothing that will slow your addon down or add delays aside from what you yourself put in.

Last edited by Nibelheim : 04-14-13 at 07:58 AM.
  Reply With Quote
04-14-13, 08:18 AM   #29
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Originally Posted by Resike View Post
Yes, but i'm pretty sure the combat log is not "just" client sided.
The information in the combat log doesn't originate client side, but what you see IS client side; and an AddOn can only act on that information, and their related events, once it becomes client side.
  Reply With Quote
04-14-13, 01:14 PM   #30
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
In other words, there's nothing between your addon and the combat log.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
04-14-13, 11:11 PM   #31
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Resike View Post
Yeah, i understand this but when you call the "GetSomeValues()" its 90% a global blizzard function, which means you already calling a function which is limited by your latency and stuff.
This is where this thread got derailed. While both effect the game in a drastic way, CPU usage and network latency are two distinctly different matters. The argument that you can waste as much CPU time as you want because function X doesn't get its data for 250ms is a complete fallacy.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-14-13 at 11:15 PM.
  Reply With Quote
04-15-13, 01:58 AM   #32
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Nibelheim View Post
It's pure client side as far as code is concerned, because as far as addons are concerned "information appears > process information".

I don't think there's any API we can use with regards to the combat log which sends a request to the Blizzard servers for more information. All information is streamed straight to us. Which means there's nothing that will slow your addon down or add delays aside from what you yourself put in.
Well, it's just not about combat log, but different events like how else would a client know, if someone capped a base in the other side of the map?
  Reply With Quote
04-15-13, 02:56 AM   #33
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Because the server tells the client that someone capped the base, just like the server tells the client that the spell you just cast crit for X damage. However, that's completely irrelevant, because addons are not aware of the server at all. As far as addons are concerned, the base wasn't capped until the client learned about it and fired the relevant event.

Anyway, this is a really idiotic turn for this discussion to take, since nothing mentioned in this thread has anything whatsoever to do with server querying. IsInInstance gets info from the client, not the server, and select is a Lua language function and thus completely unrelated to either the client or the server.

99% of functions get info directly from the client. Even for functions like GetItemInfo where you can ask the client for information it doesn't have, and the client will ask the server for it, addons aren't aware of the server querying process -- as far as your addon is concerned, the item you asked about just doesn't exist at that time. Since you know about the server, you can program your addon to wait 5 seconds and ask the client again, but your addon can't automatically go "oh, the client doesn't have this info, it's getting it from the server, let me wait 5 seconds". Latency is a network issue; it has absolutely nothing to do with the speed of calling a function vs looking up a table value.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-15-13, 03:36 AM   #34
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
Because the server tells the client that someone capped the base, just like the server tells the client that the spell you just cast crit for X damage. However, that's completely irrelevant, because addons are not aware of the server at all. As far as addons are concerned, the base wasn't capped until the client learned about it and fired the relevant event.

Anyway, this is a really idiotic turn for this discussion to take, since nothing mentioned in this thread has anything whatsoever to do with server querying. IsInInstance gets info from the client, not the server, and select is a Lua language function and thus completely unrelated to either the client or the server.

99% of functions get info directly from the client. Even for functions like GetItemInfo where you can ask the client for information it doesn't have, and the client will ask the server for it, addons aren't aware of the server querying process -- as far as your addon is concerned, the item you asked about just doesn't exist at that time. Since you know about the server, you can program your addon to wait 5 seconds and ask the client again, but your addon can't automatically go "oh, the client doesn't have this info, it's getting it from the server, let me wait 5 seconds". Latency is a network issue; it has absolutely nothing to do with the speed of calling a function vs looking up a table value.
My point is about which function can read thoose information faster, lets see if i want to check an event like capped a base with: "CHAT_MSG_BG_SYSTEM_ALLIANCE" or "CHAT_MSG_BG_SYSTEM_HORDE" or "CHAT_MSG_RAID_BOSS_EMOTE", which events gets triggered by another "events". And if i use:

Code:
local textureIndex = select(3, GetMapLandmarkInfo(i))
if textureIndex == 128 then

end
Then i used "slow function", and i still get the information faster then before the actual event triggers.
  Reply With Quote
04-15-13, 04:35 AM   #35
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You're missing the point by a very large margin. The point is not that calling Function A can get you info faster than calling Function B under Circumstance X. The point is that calling a function at all is much slower than assigning an extra variable, and you should not call functions if you don't need to -- specifically, there is almost no reason to ever use select.

Using your example, you should not do this:

Code:
local textureIndex = select(3, GetMapLandmarkInfo(i))
if textureIndex == 128 then
   -- do something
end
Instead, you should do this:

Code:
local _, _, textureIndex = GetMapLandmarkInfo(i)
if textureIndex == 128 then
   -- do something
end
You can get the exact same information from the exact same function, without the overhead of a second function call that's completely unnecessary and does not affect the information obtained or the source of the information.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-15-13, 11:13 AM   #36
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Resike View Post
if i want to check an event like capped a base with: "CHAT_MSG_BG_SYSTEM_ALLIANCE" or "CHAT_MSG_BG_SYSTEM_HORDE" or "CHAT_MSG_RAID_BOSS_EMOTE", which events gets triggered by another "events".
You should stick with events that are related to the data you're using. If you're using map data, you should trigger from WORLD_MAP_UPDATE or another related event (there's probably a PvP-related update event more specific to base capping) instead of using chat events. Using the wrong events is likely to cause problems for your code at random since the of events firing and data updates won't always be the same. The entire reason for some events is relevant data is guaranteed to have been updated by that time.

For reference, the code that handles the entire Battleground UI (status at the top of the screen and the scoreboard) is WorldStateFrame.lua.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-15-13 at 11:21 AM.
  Reply With Quote
04-15-13, 12:27 PM   #37
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by SDPhantom View Post
You should stick with events that are related to the data you're using. If you're using map data, you should trigger from WORLD_MAP_UPDATE or another related event (there's probably a PvP-related update event more specific to base capping) instead of using chat events. Using the wrong events is likely to cause problems for your code at random since the of events firing and data updates won't always be the same. The entire reason for some events is relevant data is guaranteed to have been updated by that time.

For reference, the code that handles the entire Battleground UI (status at the top of the screen and the scoreboard) is WorldStateFrame.lua.
I mainly use "WORLD_MAP_UPDATE" with IDs (There is no any other event to check capping), since i don't want to translate the ".CHAT_MSG_" events to 12 different laguages.
But sometimes you have to use the chat events, since there is no other way to trigger then event, unless you want to reverse engineer thousad of lines of blizzard code, like when someone drops the flag in WSG or TP.

Last edited by Resike : 04-15-13 at 12:32 PM.
  Reply With Quote
04-15-13, 08:30 PM   #38
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
There's no need to "reverse engineer" anything. The source code is freely available. You can either extract it yourself using methods already posted in this forum or look online to handfuls of sites that have it available to view. I even pointed out the specific Lua file that handles their battlegrounds UI.

Extraction Method:
http://www.wowpedia.org/Viewing_Bliz...interface_code

View/Download UI Files:
https://us.battle.net/support/en/art...face-addon-kit (Multiple languages available, downloads UI in a Zip file.)
https://github.com/tekkub/wow-ui-source
http://wow.go-hero.net/framexml/builds
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-15-13 at 08:50 PM.
  Reply With Quote
04-15-13, 10:22 PM   #39
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Not sure if that's right, but the only place I ever encoutered where you can't go without select is something like this:
Code:
local func = function(...)
	local num = select(#, ...)
	for i = 1, num do
		local arg = select(i, ...)
	end
end
where you could take #{...} instead of the first select. Don't know if that's 'cheaper' though.
  Reply With Quote
04-16-13, 05:19 AM   #40
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by SDPhantom View Post
There's no need to "reverse engineer" anything. The source code is freely available. You can either extract it yourself using methods already posted in this forum or look online to handfuls of sites that have it available to view. I even pointed out the specific Lua file that handles their battlegrounds UI.

Extraction Method:
http://www.wowpedia.org/Viewing_Bliz...interface_code

View/Download UI Files:
https://us.battle.net/support/en/art...face-addon-kit (Multiple languages available, downloads UI in a Zip file.)
https://github.com/tekkub/wow-ui-source
http://wow.go-hero.net/framexml/builds
Yeah, but the battleground ui only show scores and time/reinforements remaining, nothing more, and there is no any other battleground related lua file in the framexml, so i'm guessing it's not public.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Issue with select() and IsInInstance()

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