• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

fastest way to execute a function

Status
Not open for further replies.
Level 7
Joined
Jan 30, 2011
Messages
267
i want to find the fastest, leakless way to execute a function stored in a variable
i splitted it into 3 sub-question:
1. whats the fastest way to execute a boolexpr?
2. whats the fastest way to execute a code? (code is a bit problematic actually because you can neither create code arrays nor save code in a hashtable)
3. is ExecuteFunc faster?

i allready made lists of all native functions, take take boolexpr/code as parameter

i currently tend to ForceEnumPlayersCounted

functions that take boolexpr as parameter (including those who dont actually execute the boolexpr):
JASS:
native GroupEnumUnitsOfType                 	takes group whichGroup, string unitname, boolexpr filter returns nothing
native GroupEnumUnitsOfPlayer               	takes group whichGroup, player whichPlayer, boolexpr filter returns nothing
native GroupEnumUnitsOfTypeCounted          	takes group whichGroup, string unitname, boolexpr filter, integer countLimit returns nothing
native GroupEnumUnitsInRect                 	takes group whichGroup, rect r, boolexpr filter returns nothing
native GroupEnumUnitsInRectCounted          	takes group whichGroup, rect r, boolexpr filter, integer countLimit returns nothing
native GroupEnumUnitsInRange                	takes group whichGroup, real x, real y, real radius, boolexpr filter returns nothing
native GroupEnumUnitsInRangeOfLoc           	takes group whichGroup, location whichLocation, real radius, boolexpr filter returns nothing
native GroupEnumUnitsInRangeCounted         	takes group whichGroup, real x, real y, real radius, boolexpr filter, integer countLimit returns nothing
native GroupEnumUnitsInRangeOfLocCounted    	takes group whichGroup, location whichLocation, real radius, boolexpr filter, integer countLimit returns nothing
native GroupEnumUnitsSelected               	takes group whichGroup, player whichPlayer, boolexpr filter returns nothing

native ForceEnumPlayers         		        takes force whichForce, boolexpr filter returns nothing
native ForceEnumPlayersCounted  		        takes force whichForce, boolexpr filter, integer countLimit returns nothing
native ForceEnumAllies          		        takes force whichForce, player whichPlayer, boolexpr filter returns nothing
native ForceEnumEnemies         		        takes force whichForce, player whichPlayer, boolexpr filter returns nothing
			
native TriggerRegisterEnterRegion 		        takes trigger whichTrigger, region whichRegion, boolexpr filter returns event
native TriggerRegisterLeaveRegion 		        takes trigger whichTrigger, region whichRegion, boolexpr filter returns event

native TriggerRegisterPlayerUnitEvent 		    takes trigger whichTrigger, player whichPlayer, playerunitevent whichPlayerUnitEvent, boolexpr filter returns event
native TriggerRegisterFilterUnitEvent 		    takes trigger whichTrigger, unit whichUnit, unitevent whichEvent, boolexpr filter returns event
native TriggerRegisterUnitInRange 		        takes trigger whichTrigger, unit whichUnit, real range, boolexpr filter returns event
native TriggerAddCondition    			        takes trigger whichTrigger, boolexpr condition returns triggercondition

native EnumDestructablesInRect     		        takes rect r, boolexpr filter, code actionFunc returns nothing
	
native And              			            takes boolexpr operandA, boolexpr operandB returns boolexpr
native Or               			            takes boolexpr operandA, boolexpr operandB returns boolexpr
native Not              			            takes boolexpr operand returns boolexpr

functions that take code as parameter (including those who dont actually execute the code):
JASS:
native ForGroup			         takes group whichGroup, code callback returns nothing
native ForForce			         takes force whichForce, code callback returns nothing
native EnumDestructablesInRect	 takes rect r, boolexpr filter, code actionFunc returns 

native TimerStart		         takes timer whichTimer, real timeout, boolean periodic, code handlerFunc returns nothingnothing
native Condition		         takes code func returns conditionfunc
native Filter			         takes code func returns filterfunc
native TriggerAddAction		     takes trigger whichTrigger, code actionFunc returns triggeraction
 
Level 7
Joined
Jan 30, 2011
Messages
267
There is also a native that takes the function name as a string and calls it (in a new thread?).
thats ExecuteFunc, my 3rd question ;)

I think attaching the code to a constant trigger as a boolexpr (once created, never destroyed) and then running the trigger was found to be the fastest.
used this method til now, but found out that trigger conditions leak
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
JASS:
call ExecuteFunc takes string functionname returns nothing?

its amongst the slowest functions in Jass because it starts it in new thread and also it must change the string to function

I would maybe use trigger for this:
JASS:
local trigger t = CreateTrigger()
call TriggerAddCondition(t, Condition(your function variable))
// or if you have boolexpr
// call TriggerAddCondition(t, yourboolexpr)
// but Im not sure it will work tho
call TriggerEvaluate(t)
call DestroyTrigger(t)
set t = null

but it may not be the fastest way
 
Level 7
Joined
Jan 30, 2011
Messages
267
as dsg said and ive heard that too: TriggerAddCondition + TriggerEvaluate is the fastest way
but destroying the trigger doesnt destroy the triggercondition that you receive from TriggerAddCondition
=> its not leakless
 
Level 7
Joined
Jan 30, 2011
Messages
267
take a look at nestharus damage event + damage modification effect
afaik nestharus has allways put much effort into making his codes fast and leakless
in PriorityEvent hes using TriggerEvaluate to call the boolexpr, because code being registered to a PriorityEvent cant be unregistered
but a damage modification effect can be destroyed again, so hes using ForceEnumPlayersCounted there, because it doesnt allocate a triggercondition
 
Status
Not open for further replies.
Top