HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Which is faster?

03-22-2008, 05:07 PM#1
notsoexpert
Which one of these methods is faster:
Collapse JASS:
function conditions takes nothing returns boolean
   return GetSpellAbilityId() == 'A000'
endfunction
function actions takes nothing returns nothing
// actions
endfunction
function InitTrig takes nothing returns nothing
   local trigger tr = CreateTrigger()
   call TriggerRegisterAnyUnitEventBJ(tr,EVENT_PLAYER_UNIT_SPELL_EFFECT)
   call TriggerAddCondition(tr,Condition(function conditions))
   call TriggerAddAction(tr,function actions)
   set tr = null
endfunction
or this:
Collapse JASS:
function actions takes nothing returns boolean
// declarations
if GetSpellAbilityId() == 'A000' then
// actions
endif
return false
endfunction
function InitTrig takes nothing returns nothing
local trigger tr = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(tr,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(tr,Condition(function actions))
set tr = null
endfunction

I'm assuming the second one.
Is it necessary to store the boolexpr in a variable in inittrigs? Does anything in InitTrig functions leak? If so, how do I clear them? I'm trying to become as optimized as possible.

EDIT: Couple more questions: Does nulling the trigger variable do anything productive? If setting the boolexpr in a variable is a good thing, should I null that variable after adding it to the trigger?
03-22-2008, 05:12 PM#2
RolePlaynGamer
the first one should be fastest.
03-22-2008, 05:13 PM#3
Here-b-Trollz
You shouldn't null the trigger variable, since you aren't destroying the trigger, nulling it won't do anything.

The second one should be faster, but might not be, depending on if an internal if and two function calls is faster than an external if and one function call. Basically, when a trigger is run:

Collapse JASS:
if(TriggerEvaluate())then
    call TriggerExecute()
endif

But it's done internally. You'd have to benchmark to be sure, although really it shouldn't matter for spellmaking.

Storing the boolexpr is only a good idea if you are using vJass - otherwise, it's a waste of time. And, if you are only going to use that boolexpr once, don't even bother.
03-22-2008, 05:22 PM#4
Captain Griffen
The first is faster, as no thread has to be created. (WRONG)

Now, moving everything into the conditions thread? Has some draw backs (don't put any waits in the thread, for one), but that might be faster.

EDIT: First paragraph of this is wrong.
03-22-2008, 05:29 PM#5
notsoexpert
Quote:
Storing the boolexpr is only a good idea if you are using vJass

I am, and why would it be any different if I was using normal Jass?

Quote:
And, if you are only going to use that boolexpr once, don't even bother.

Does this mean that the difference is negligible but present or not existent? If it helps, I'll do it, no matter how trivial.

Quote:
The first is faster, as no thread has to be created.

Now, moving everything into the conditions thread? Has some draw backs (don't put any waits in the thread, for one), but that might be faster.

Am I wrong, or did you just tell me one is faster but the other might be faster?
03-22-2008, 05:36 PM#6
Here-b-Trollz
If you are using vJass, you have easy global manipulation, so a global boolexpr that just returns GetSpellAbilityId()=='A000' would be good if you needed to use it more than once. However, since you generally only need one trigger per spell, there would be no performance boost in storing it - actually, a performance drop.

If, however, you are doing something periodically, like a group enum, for example, that requires a filter, you should store the boolexpr, and refer to the variable, to avoid the extra function call.

And why are you so 'OMG OPTIMIZE!!!' about this? It looks to me like you are making spells, and there's only a certain degree of optimization necessary in such case.
03-22-2008, 05:41 PM#7
notsoexpert
More curiosity than anything else, and I like to know exactly what I'm dealing with and what my options are while making my spells or triggers or whatever I decide to do next. The spellmaking is just an example.

Thanks for clarifying though.
03-22-2008, 10:13 PM#8
MaD[Lion]
i think the 2nd is faster, cus i read somewhere tat using just condition is faster. At least Vexorian said tat.
03-22-2008, 10:17 PM#9
Captain Griffen
Hmm...I just looked again, and, yes, second is likely faster. I was skim reading and took 'actions' to be an action (I must stop doing that, even when in a hurry).

Just watch out with this that you don't put any waits in the thread, as it isn't a real thread.

Quote:
Am I wrong, or did you just tell me one is faster but the other might be faster?

Would seem I did.
03-22-2008, 10:35 PM#10
RolePlaynGamer
Hmm if the second one is faster why do we use conditions?
03-22-2008, 10:42 PM#11
Here-b-Trollz
Because they are easy to configure? There are multiple reasons, mostly though that we can move them around (since they are boolexprs) and they are handles. Much more convenient than writing out code, etc.
03-22-2008, 10:45 PM#12
Captain Griffen
Conditions are faster.

Why we use actions is a better question. And the answer is that you can use waits in them, and the efficiency saving isn't that important.
03-22-2008, 10:46 PM#13
RolePlaynGamer
Yea i know... But i'll keep using conditions anyway..
03-22-2008, 11:02 PM#14
Vexorian
The second is faster.

Unless you had a lot of other spells in the map the first one would be better.

My take is: Let's forget about actions, entirely, if you ever need waits, use .execute and be happy.
03-23-2008, 12:05 AM#15
Toadcop
Quote:
Unless you had a lot of other spells in the map the first one would be better.
you mean not directly alot spells you mean alot of triggers with spell effect event =) yes but it's can be solved easly via custom "event manager" (aka spells function will be executed from some array slot) so you could have up too 8K spell with out a problem (ofc you would have maybe ~5MB of jass code ^^)

and ofc second example is faster TT. so about 2 times or more... ~3
triggerevaluate ~11 of something
triggerexecute ~22 of something

so
1 example =
~33 of something
the second
~11 of something + minor calcs.
// thats just examples.