• 🏆 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!

[General] Maximum Loop Per Instance

Status
Not open for further replies.
Level 33
Joined
Mar 27, 2008
Messages
8,035
Maximum Loop Per Instance [SOLVED]

I did a research and some experimenting just how much value can a loop goes in a single run.

It seems that a maximum loop per instance is 7894 times in a single-run.

What I did, is this;
- My end number of the loop is 10,000
- My initial number of the loop is 1
- I put a dummy unit with HP 10,000 (with no HP regen at all)
- I used a trigger to damage the target (ignores armor and magical reduction type of damage) (the damage is 1)
- Result: The unit's HP is 2106 (which means 10,000 - 7894 = 2106)

EDIT:
And now I can do a maximum of 10,714 loop per single instance dammit.

Solution:
If I want to bypass this limit, let's say I want the loop to be made 10,000 times, what algorithm/method/formula should I use ?

Can you guys do a loop per instance for 100,000 in single-run ?


Each test gives me various of results, just close this thread..
 
Last edited:
Level 26
Joined
Aug 18, 2009
Messages
4,097
A thread can do up to 300k micro operations before halting. Everything costs some like function calls, variable assignment/reading, with/without array, evaluation of control structures etc.

wc3jass.com is no more, I had always linked to a topic there but here is some insight too.

To reset the counter, you can either start a new thread like with TriggerExecute, ExecuteFunc, ForGroup, TimerStart, firing an event, ... or put in a refreshing TriggerSleepAction.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Did you know the abusing bugs of Item Bonus Health and Item Bonus Mana ability ?

Where you can increase/decrease max HP/MP of a unit just by adding them the ability and level it up, afterwards, just remove it.

Well, you see, I tried to do a 10,000 loops of:
Add ability
Level it up
Remove it

The varies is with the "level it up" method.

You see, with the function SetUnitAbilityLevel, I can achieve up to 7894 of loops before it is auto terminated

With the function IncUnitAbilityLevelSwapped, I can achieve up to 10,000 loops before it is auto terminated.

With the function IncUnitAbilityLevel, I can achieve up to 10,714 loops before it is auto terminated.

I don't know whether the function plays role in this, or is it just my eyes.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
SetUnitAbilityLevel takes one more argument --> more ops for the jass VM.

Since you state that IncUnitAbilityLevelSwapped is even cheaper, you probably read some variables/functions when determining the third argument for SetUnitAbilityLevel.

Anyway, split it up. Costly header functions should be outsourced anyway to not create a problem for the locations of appliance.

You would do something like this:

JASS:
function addLife_exe takes nothing returns nothing
    local integer i = GLOBAL_ITERATOR

    loop
        exitwhen (i > iEnd)
        exitwhen (i > MAX_ITERATIONS_PER_EXE)

        do actions

        i = i + 1
    endloop

    if (not (i > iEnd)) then
        GLOBAL_ITERATOR = i

        execute addLife_exe
    endif
endfunction

function addLife takes nothing returns nothing
    GLOBAL_ITERATOR = 0

    execute addLife_exe
endfunction
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
By doing this experiment, I can see that JASS is far more superior than GUI.

You see, I did these 3 actions;
  • Loop - Actions
    • Unit - Add AR_AddHP to AR_Unit
    • Unit - Set level of AR_AddHP for AR_Unit to 2
    • Unit - Remove AR_AddHP from AR_Unit
I only got a maximum of 4762 number of loops before it terminates

And when compared to these;
  • Loop - Actions
    • Custom script: call UnitAddAbility(udg_AR_Unit, udg_AR_AddHP)
    • Custom script: call IncUnitAbilityLevel(udg_AR_Unit, udg_AR_AddHP)
    • Custom script: call UnitRemoveAbility(udg_AR_Unit, udg_AR_AddHP)
I got the usual 10,714 maximum loops

How big difference is it ?

Now I need to know why they differ so much ?

It's the same function/action is used after all.

And I wonder why they are terminated ?
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Make sure once the GUI is converted to jass the functions which are used are not BJ ones.
In other words if they are not custom functions from blizzard.j which use the native functions from common.j

If they are BJ the answer is obvious, else you've probably doing mistakes, like using extra stuff.
 
Status
Not open for further replies.
Top