• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

What causes a map to lag?

Status
Not open for further replies.
Level 3
Joined
Nov 28, 2008
Messages
24
Hi. I'm just wondering, what causes a map to lag (triggering part) other than leaks and over effects? I know this is a stupid question.....but can anyone please tell me or post a link to where I can read about it myself?

Thanks for the help and sorry for my bad english.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Too much actions at once.

If you have a trigger that runs every 0.01 seconds, set the event to every 0.03 or 0.04 seconds (or even slower for systems that really don't need such a high interval).
If a trigger lags only the first time it's activated, you might want to preload it (just run it once very early in the game so the initial lag is gone).
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,217
Leaks and over effects do not cause lag unless they drop your frame rate or cause you to no longer keep up with other players.

The usual causes of lag are too much net traffic. The damage AoE native for example causes not traffic and if run enough at once will cause the game to have huge lag. Additionally, TriggerSleepAction causes net traffic so running a hundred of them at once will result in lag. Other code like trackables can also cause net traffic due to them feeding in mouse data.

If you mean what causes frame dropping (poor performance), then anything that is computationally intensive. Running algerthims on groups of all units on the map with O(n^2) or worse efficency multiple of times a second is an easy way to make the game drop frames. Additionally, having hundreds of units with global range and projectile attacks start attacking at once will cause a lot of frame skipping as the target aquisition algerthim is demanding and the projectiles cause a lot of objects to be updated each internal frame.

Computers are only capable of executing billions of instructions per second. If you do anything which uses huge numbers of instructions per second, the game will be forced to skip frames (dropping the render time to keep up which means you cann ot respond for another frame) and eventually slow down (causing lag) inorder to do everything you want done. Running code with Orders of n^2 or worse (n! being about the worst you will encounter outside of really complex programs) will easilly eat up your processor time.

WC3 runs at slightly less (but about) 60 frames per second. This means that inorder for a frame not to be dropped, it will have to run all the instructions to prepare the next frame within 0.016... seconds. This includes trigger code that runs as WC3 runs largly sequentially (limited parallelisim). If it fails to do everything within that time, it will drop the frame render code (your CPU is loaded heavilly for generating the game graphics) inorder to hope that it will allow it to catch up. There is some biased towards rendering frames for you so that you are not completly blind (like 1 frame every 60 internal frames is force rendered) Obviously if it is dropping almost every frame, it is likly you can not keep up with the game process so it will be forced to drop the internal FPS down to what your processor can handle (this causes lag for other people as they run in 60 FPS bursts followed by paused delay waiting for you which will cause you to drop eventually).

Optimizing your map is a good way to improve performance. This is the process of removing redundant instructions or changing the solution to a problem so that it is computationally less complex. Eg, keeping track of the number of units of a type in a counter instead of each time counting all units of a certain type on the map is a great optomization.

Do not be afraid to let the odd frame get dropped during demanding times but you should aim for near constant 60 FPS all game (on modern machines, older can be expected to do 40-50).
 
Level 3
Joined
Nov 28, 2008
Messages
24
Wow! Thanks guys for helping out. Appreciated it a lot. But I'm still not sure about something:

Every * marks a new question

*
Additionally, TriggerSleepAction causes net traffic so running a hundred of them at once will result in lag.
-So, what should I replace them with?

*
  • Some Trigger
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
-I know this causes lag if there's too many of this event running at the same time (correct me if I'm wrong). So, how many of this event can I have at most?
-If a map requires a lot of 'Every 5.00 seconds of game time' check, what should I do? Does this event:
  • Some Trigger
    • Events
      • Time - Timer Expires
    • Conditions
    • Actions
causes less lag than 'Every 5.00 seconds of game time' event? If So, how many of 'Timer Expires' event can I have at most? If not, what do I use to replace those events?
-Does the duration of the interval affect the map's performance too?

*
  • Some Trigger
    • Events
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
-I used this in my map to check the number of enemy units alive. If the number of enemy units alive is more than the 50, then it will remove random 5 enemy units. At the beginning of the game, it seems fine, no lag. But, when nearing the end, the game started to lag (short period of lags) every 5-10 seconds. I was wondering if this causes the lag and if it does, what should I do to the trigger to lessen the lag?
-Does '(Units in (Playable map area))' affect the map's performance too? If i use '(Units in (Playable map area))', will it cause more lag than 'Units owned by Player 1 (Red))'
-
JASS:
set a = GetUnitsInRectAll(GetPlayableMapRect())
  set b = FirstOfGroup(a)
      loop
         exitwhen b == null
            (Actions)
         set b = null
         set b = FirstOfGroup(a)
      endloop
Does the script above causes lag too?

*
  • Some Trigger
    • Events
      • Unit - A unit Dies/A unit Finishes construction/A unit Starts the effects of an ability/A unit Is attacked/......
    • Conditions
    • Actions
-I was wondering if I have 10 triggers with this event, will it lag too? If yes, should I merge all the triggers into one and use this event once only? But what if, the actions and conditions are very complex (as in a lot of actions and conditions). Will it slow down the performance too?

Thanks for the help. I will truely, really, eternally appreciate all the help.
And 1 more stupid question.....how do you + other user's rep? XD:xxd:

Oh....and it took me 1 hour to finish this post....hahaha how silly....
 
Level 12
Joined
Oct 7, 2010
Messages
447
click the
reputation.gif
at the post of the person, right under his/her avatar to +rep. :wink:
 
Level 3
Joined
Nov 28, 2008
Messages
24
click the
reputation.gif
at the post of the person, right under his/her avatar to +rep. :wink:

OWH...missed that button...lol
Thanks for the rep! Really appreciated it!

obviously, as explained by the people here, things at the same time.
also, many units existing at the same time, each using high polygon models.

But then, what are the solutions?
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,217
None of the above cause lag. Lag is response latency. Although low frame rate does cause increased repsonse latency (as you can only issue actions every frame), it is not lag directly and you need very low frame rate (less than 10 per second) for it to ever be the major factor in lag (as you have about 100 ping in multiplayer games which caps your lags lowbounds).

Timers and timing events do not cause lag as they opperate net trafic independantly. They are also linear so running a lot of them will not make noticable frame skiping but they can cause frame skipping if you run a lot of them every second with complex code responses (eg moving a thousand units 100 times a second).

Pick every unit on map is extreemly bad for performance as the group generation is complex and then you perform a O(n) action complexity from it. If you leak the group like the code you gave, then that will make allocation slower through the game (as less free memory is available). Running this 100 times per second will easilly cause frame skipping to occur on large maps.

The jass script given will ALWAYS cause frame dropping as it is basically an infinite loop (you got the algerthim wrong, it is loop, get first unit to var, check var unit for the break, actions on var unit and then remove var unit from group). In anycase it is slower than running the enum on the group due to the way groups work. It also leaked the same group.

Events do not cause lag outside of net traffice related ones (which the examples were not). Weather they cause frame skipping or not is up to the code you run on them.
 
Level 3
Joined
Nov 28, 2008
Messages
24
None of the above cause lag. Lag is response latency. Although low frame rate does cause increased repsonse latency (as you can only issue actions every frame), it is not lag directly and you need very low frame rate (less than 10 per second) for it to ever be the major factor in lag (as you have about 100 ping in multiplayer games which caps your lags lowbounds).

Timers and timing events do not cause lag as they opperate net trafic independantly. They are also linear so running a lot of them will not make noticable frame skiping but they can cause frame skipping if you run a lot of them every second with complex code responses (eg moving a thousand units 100 times a second).

Pick every unit on map is extreemly bad for performance as the group generation is complex and then you perform a O(n) action complexity from it. If you leak the group like the code you gave, then that will make allocation slower through the game (as less free memory is available). Running this 100 times per second will easilly cause frame skipping to occur on large maps.

The jass script given will ALWAYS cause frame dropping as it is basically an infinite loop (you got the algerthim wrong, it is loop, get first unit to var, check var unit for the break, actions on var unit and then remove var unit from group). In anycase it is slower than running the enum on the group due to the way groups work. It also leaked the same group.

Events do not cause lag outside of net traffice related ones (which the examples were not). Weather they cause frame skipping or not is up to the code you run on them.

Thanks a lot! It really helped a lot! Thanks for your time and dedication. Will +rep!
 
Status
Not open for further replies.
Top