Mission Optimisation: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Add marker management trick)
m (Text replacement - "[[Arma 3 " to "[[Arma 3: ")
 
(27 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{SideTOC}}
{{TOC|side}}
{{ Informative | This page is about [[Mission Optimisation]]. For ''scripting'' optimisation, see [[Code Optimisation]]. }}
{{Feature|informative|This page is about [[Mission Optimisation]]. For ''scripting'' optimisation, see [[Code Optimisation]].}}
== Introduction ==


This article will try to be a general guide about improving your '''mission's''' performance.<br>
This article will try to be a general guide about improving your '''mission's''' performance.<br>
As usual, moderation is the key; do not expect to find on this page a magical solution that makes it possible to run thousands of AI at 144 FPS. Everything comes at a cost, the tweaks here will simply allow you to locate issues and calibrate your mission properly.
As usual, moderation is the key; do not expect to find on this page a magical solution that makes it possible to run thousands of AI at 240 FPS.
Everything comes at a cost, the tweaks here will simply allow you to locate issues and calibrate your mission properly.




== Before anything ==
== Before Anything ==


Before optimising anything, make sure you do not have any performance issue running the game itself:
Before optimising anything, make sure you do not have any performance issue running the game itself:
* Read [[Arma 3: Performance Optimisation]]
* Open the editor, place a unit in the area you like and test your computer.
* Open the editor, place a unit in the area you like and test your computer.
** You can get current FPS in {{arma3}} by going into '''video options''' or using [[diag_fps]]
** You can get current FPS in {{arma3}} by going into '''video options''' or using [[diag_fps]]
** '''Steam''' allows you to display FPS in a screen corner, in ''Settings &gt; In game &gt; FPS Counter''
** '''Steam''' allows you to display FPS in a screen corner, in ''Settings &gt; In game &gt; FPS Counter''
* Use (unofficial) Performance Guides to get better performances:
* Use (unofficial) Performance Guides to get better performances:
** [https://steamcommunity.com/sharedfiles/filedetails/?id=1731305438       {{arma3}} performance guide]
** {{Link|https://steamcommunity.com/sharedfiles/filedetails/?id{{=}}1731305438|{{arma3}} performance guide}}
** [https://www.moddb.com/forum/thread/arma-2-ultimate-tweak-thread         {{arma2}} performance guide]
** {{Link|https://www.moddb.com/forum/thread/arma-2-ultimate-tweak-thread|{{arma2}} performance guide}}
** [https://forums.bohemia.net/forums/topic/50167-pc-optimization-for-arma/ {{arma}} performance guide]<!--
** {{Link|https://forums.bohemia.net/forums/topic/50167-pc-optimization-for-arma/|{{arma1}} performance guide}}<!--
** [ {{ofp}}  performance guide]
** [{{ofp}}  performance guide]
-->
-->
* Play your mission in singleplayer. If your mission runs fine, its network messages might very well be the issue. See [[Multiplayer Scripting]] for good practice tips.
* Play your mission in singleplayer. If your mission runs fine, its network messages might very well be the issue. See [[Multiplayer Scripting]] for good practice tips.
Line 23: Line 24:
** Lower your graphical settings (resolution, textures). If you get way better performances, at least your '''GPU''' limits you.
** Lower your graphical settings (resolution, textures). If you get way better performances, at least your '''GPU''' limits you.
** If the game keeps having low FPS when running @ 1024×768/low textures then your CPU is most likely the issue. Mission scripts may be performance-hogging too.
** If the game keeps having low FPS when running @ 1024×768/low textures then your CPU is most likely the issue. Mission scripts may be performance-hogging too.
{{ Important | Please note that [[viewDistance|view distance]] (among other settings) impacts both GPU and CPU! }}
{{Feature|important|Please note that [[viewDistance|view distance]] (among other settings) impacts both GPU and CPU!}}
{{ Informative | [[viewDistance|View distance]] can be separately set for each clients independently from the server's value through scripting.<br>
{{Feature|informative|[[viewDistance|View distance]] can be separately set for each clients independently from the server's value through scripting.<br>This can make or break performance for the client.}}
This can make or break performance for the client. }}




== Creating your mission ==
== Creating your Mission ==


* Be sure to create your scripts with the latest available commands and functions.
* Be sure to create your scripts with the latest available commands and functions.
** In {{arma3}} use [[remoteExec]]&nbsp;/&nbsp;[[remoteExecCall]] and '''DITCH [[BIS_fnc_MP]] FOR GOOD!''' See [[Arma 3 Remote Execution]] for more information.
** In {{arma3}} use [[remoteExec]]&nbsp;/&nbsp;[[remoteExecCall]] and '''DITCH [[BIS_fnc_MP]] FOR GOOD!''' See [[Arma 3: Remote Execution]] for more information.
** In {{arma2}} network communication is done using the [[Arma 2: Multiplayer Framework]].
** In {{arma2}} network communication is done using the [[Arma 2: Multiplayer Framework]].
* Use the available frameworks and functions for each topic, unless you replace them by third-party ones:
* Use the available frameworks and functions for each topic, unless you replace them by third-party ones:
** [[Arma 3 Respawn]]
** [[Arma 3: Respawn]]
** [[Arma 3 Revive]]
** [[Arma 3: Revive]]
** [[Arma 3 Task Framework]]
** [[Arma 3: Task Framework]]
** [[Arma 3 Animated Briefing]]
** [[Arma 3: Animated Briefing]]
** [[Arma 3 Animated Opening]]
** [[Arma 3: Animated Opening]]
** [[Arma 3 Dynamic Groups]]
** [[Arma 3: Dynamic Groups]]
** [[Arma 3 Key Frame Animation]]
** [[Arma 3: Key Frame Animation]]
** and most importantly: [[Functions]]
** and most importantly: [[Functions]]




== Performance impact table ==
== Performance Impact Table ==


{{Informative|
{{Feature|informative|
: {{colorball|red|1.125}}    means a heavy impact on performance<br>
: {{Colorball|red|1.125}}    means a heavy impact on performance<br>
: {{colorball|orange|1.125}} means an average impact<br>
: {{Colorball|orange|1.125}} means an average impact<br>
: {{colorball|green|1.125}}  means little to no performance impact.
: {{Colorball|green|1.125}}  means little to no performance impact.
}}
}}


{|class="bikitable"
{| class="wikitable align-center-col-2 align-center-col-3 align-center-col-4"
! Topic
! Topic
! CPU
! CPU
Line 61: Line 61:
|
|
==== AI unit quantity ====
==== AI unit quantity ====
| {{colorball|red}}
| {{Colorball|red}}
| {{colorball|green}}
| {{Colorball|green}}
| {{colorball|orange}}
| {{Colorball|orange}}
|
|
* Use [[createAgent|Agents]] whenever possible
* Use [[createAgent|Agents]] whenever possible
* The more units there are, the more network updates there will be - hence the impact on both CPU and network.
* The more units there are, the more network updates there will be - hence the impact on both CPU and network.
* If a client has a low-end machine, they shouldn't lead a group of many AIs as these would then be locally computed.
* If a client has a low-end machine, they shouldn't lead a group of many AIs as these would then be locally computed.
* [[Arma 3 Dynamic Simulation]] allows you to freeze AI that are distant from players. Many distance settings should be set according to the mission.
* [[Arma 3: Dynamic Simulation]] allows you to freeze AI that are distant from players. Many distance settings should be set according to the mission.
{{ Informative | If you own more than one average computer, you could consider [[Arma 3 Headless Client|Headless client]] to offload AI from the server. }}
{{ Feature | Informative | If you own more than one average computer, you could consider [[Arma 3: Headless Client|Headless client]] to offload AI from the server. }}
|-
|-
|
|
==== Object quantity ====
==== Object quantity ====
| {{colorball|orange}}
| {{Colorball|orange}}
| {{colorball|orange}}
| {{Colorball|orange}}
| {{colorball|orange}}
| {{Colorball|orange}}
| The less objects, the more FPS you will have.
| The less objects, the more FPS you will have.
* Lower the quantity of objects in the mission, such as:
* Lower the quantity of objects in the mission, such as:
Line 85: Line 85:
* Lower [[viewDistance]]
* Lower [[viewDistance]]
* Lower [[setTerrainGrid| terrain details]]
* Lower [[setTerrainGrid| terrain details]]
* Lower the [[Arma 3 Dynamic Simulation|Dynamic Simulation]] treshold
* Lower the [[Arma 3: Dynamic Simulation|Dynamic Simulation]] treshold
* Use [[Arma 3 Simple Objects|Simple Objects]]
* Use [[Arma 3: Simple Objects|Simple Objects]]
* Use '''Garbage Collection''' in order to automatically delete bodies and wreckages:
* Use '''Garbage Collection''' in order to automatically delete bodies and wreckages:
** {{arma3}}'s Eden-integrated [[Description.ext#Corpse_.26_wreck_management|Garbage Collection]]
** {{arma3}}'s Eden-integrated [[Description.ext#Corpse_.26_wreck_management|Garbage Collection]]
** {{arma2}}'s [[Garbage Collector]]
** {{arma2}}'s [[Garbage Collector]]
** {{tkoh}}'s [[BIS_fnc_GC]]
** {{tkoh}}'s [[BIS_fnc_GC]]
{{ Informative | Only the ''on-screen'' objects will strongly impact GPU. }}
{{ Feature | Informative | Only the ''on-screen'' objects will strongly impact GPU. }}
|-
|-
|
|
==== General script mistakes ====
==== General script mistakes ====
| {{colorball|orange}}
| {{Colorball|orange}}
| {{colorball|green}}
| {{Colorball|green}}
| {{colorball|green}}
| {{Colorball|green}}
| Having too many scripts running is a cause for severe performance issues and execution delays in singleplayer as well as multiplayer.
| Having too many scripts running is a cause for severe performance issues and execution delays in singleplayer as well as multiplayer.
* You can track the number of running scripts using [[diag_activeScripts]]; you can also use:
* You can track the number of running scripts using [[diag_activeScripts]]; you can also use:
Line 105: Line 104:
** [[diag activeMissionFSMs]]
** [[diag activeMissionFSMs]]
* A common bad practice is to [[spawn]] a function for each units that need it; the good practice would be to have a single script working with an array of units, array that is edited (unit added/removed) whenever needed:<!--
* A common bad practice is to [[spawn]] a function for each units that need it; the good practice would be to have a single script working with an array of units, array that is edited (unit added/removed) whenever needed:<!--
--><code>{ [[_x]] [[spawn]] _myCode; } [[forEach]] _units; {{cc|bad}}<br><!--
--><sqf>
-->_units [[spawn]] _myCode; {{cc|good}}</code><!--
{ _x spawn _myCode; } forEach _units; // bad
_units spawn _myCode; // good
</sqf><!--
-->You can use [[diag_activeSQFScripts]] to ensure you are not clogging your CPU with multiple instances of the same script.
-->You can use [[diag_activeSQFScripts]] to ensure you are not clogging your CPU with multiple instances of the same script.
* '''Not compiling your scripts:''' running multiple times the same script with [[execVM]] will make the game read the file every single time; This is an issue, especially if you execute it frequently.<br><!--
* '''Not compiling your scripts:''' running multiple times the same script with [[execVM]] will make the game read the file every single time; This is an issue, especially if you execute it frequently.<!--
--><code>[[while]] { [[sleep]] 5; [[alive]] [[player]] } [[do]] { [[player]] [[execVM]] "myScript.sqf"; }; {{cc|bad}}<br><br><!--
--><sqf>
-->[[private]] _myScript = [[compile]] [[preprocessFileLineNumbers]] "myScript.sqf";<br><!--
while { sleep 5; alive player } do { player execVM "myScript.sqf"; }; // bad
-->[[while]] { [[sleep]] 5; [[alive]] [[player]] } [[do]] { [[player]] [[spawn]] _myScript; }; {{cc|good}}</code>
 
private _myScript = compile preprocessFileLineNumbers "myScript.sqf";
while { sleep 5; alive player } do { player spawn _myScript; }; // good
</sqf>
|-
|-
|
|
==== High-frequency scripts ====
==== High-frequency scripts ====
| {{colorball|red}}
| {{Colorball|red}}
| {{colorball|green}}
| {{Colorball|green}}
| {{colorball|green}}
| {{Colorball|green}}
| Checking a condition too often is usually a source of poor performance. Does your code execution need to be frame-perfect, or can you afford a delay of a few seconds?
| Checking a condition too often is usually a source of poor performance. Does your code execution need to be frame-perfect, or can you afford a delay of a few seconds?
* A [[while]]-loop checking without a minimum loop-[[sleep]] time is usually a sign of bad conception.<!--
* A [[while]]-loop checking without a minimum loop-[[sleep]] time is usually a sign of bad conception.<!--
--><code>[[while]] { [[true]] } {{cc|bad if you don't know what you are doing}}<br><!--
--><sqf>
-->[[while]] { [[alive]] [[player]] } {{cc|better}}<br><!--
while { true } // bad if you don't know what you are doing
-->[[while]] { [[sleep]] 1 ; [[alive]] [[player]] } {{cc|perfect}}</code>
while { alive player } // better
* [[trigger|Triggers]] check their set condition '''every 0.5 second''' (hardcoded value). If a large area is covered or condition code is too complex, this can become an issue; the triggers should then be converted to scripts if possible.
while { sleep 1 ; alive player } // perfect
* [[trigger|Triggers]] can be made '''Server-Side only''' to save clients' resources.
</sqf>
{{Important | All of the mission-related calculation (objectives, completion distance, etc.) must be done '''server-side'''. Local effects should be calculated '''client-side'''.}}
* By default, [[Trigger]]s check their set condition '''every 0.5 second'''. If a large area is covered or condition code is too complex, this can become an issue; the triggers should then be converted to scripts if possible. Since {{GVI|arma3|2.00}} it is possible to change trigger intervals, either via [[Eden_Editor:_Entity_Attributes|trigger attributes]] in [[:Category:Eden Editor|3DEN]], or via the scripting command [[setTriggerInterval]].
* [[Trigger]]s can be made '''Server-Side only''' to save clients' resources.
{{Feature | important | All of the mission-related calculation (objectives, completion distance, etc.) must be done '''server-side'''. Local effects should be calculated '''client-side'''.}}
|-
|-
|
|
==== High-frequency network messages ====
==== High-frequency network messages ====
| {{colorball|orange}}
| {{Colorball|orange}}
| {{colorball|green}}
| {{Colorball|green}}
| {{colorball|red}}
| {{Colorball|red}}
|
|
* Use [[publicVariable]] wisely; for specific cases, consider [[publicVariableServer]]&nbsp;/&nbsp;[[publicVariableClient]]
* Use [[publicVariable]] wisely; for specific cases, consider [[publicVariableServer]]&nbsp;/&nbsp;[[publicVariableClient]]
* Creating [[createUnit|units]]/[[createVehicle|vehicles]] globally implies a network synchronisation, keep them to a minimum / at one-point in the mission.
* Creating [[createUnit|units]]/[[createVehicle|vehicles]] globally implies a network synchronisation, keep them to a minimum / at one-point in the mission.
* Keep [[:Category:Commands with global effects|global effect]] commands to a minimum:
* Keep [[Multiplayer Scripting#Locality|global effect]] commands to a minimum:
** e.g a [[setPos]] will synchronise the unit position to every client, a good practice is to use these commands punctually. If you need a frequent "set position" you may want to look at [[attachTo]] depending on your usage.
** e.g a [[setPos]] will synchronise the unit position to every client, a good practice is to use these commands punctually. If you need a frequent "set position" you may want to look at [[attachTo]] depending on your usage.
** [[Multiplayer Scripting#Locality|global]] [[:Category:Command Group: Markers|marker commands]] always send ''all'' the marker's information. If you are creating/updating many markers e.g server-side, edit them with [[Multiplayer Scripting#Locality|local]] commands, except the last one (that will be global) to send the whole marker's status over the network, once.
** [[Multiplayer Scripting#Locality|global]] [[:Category:Command Group: Markers|marker commands]] always send ''all'' the marker's information. If you are creating/updating many markers e.g server-side, edit them with [[Multiplayer Scripting#Locality|local]] commands, except the last one (that will be global) to send the whole marker's status over the network, once.
Line 142: Line 148:
|
|
==== Unscheduled code ====
==== Unscheduled code ====
| {{colorball|red}}
| {{Colorball|red}}
| {{colorball|green}}
| {{Colorball|green}}
| {{colorball|green}}
| {{Colorball|green}}
| [[Scheduler#Unscheduled_Environment|Unscheduled code]] can have a high impact on the framerate, as such code is not subject to the [[Scheduler|scheduler]]'s management (as its name suggests) and will run without limitation. Cyclic unscheduled low-performance code can make the game unplayable, up to freezing it.
| [[Scheduler#Unscheduled_Environment|Unscheduled code]] can have a high impact on the framerate, as such code is not subject to the [[Scheduler|scheduler]]'s management (as its name suggests) and will run without limitation. Cyclic unscheduled low-performance code can make the game unplayable, up to freezing it.
* As only time-critical scripts should run unscheduled, [[spawn]] any other code from unscheduled environment once you have the required results:<!--
* As only time-critical scripts should run unscheduled, [[spawn]] any other code from unscheduled environment once you have the required results:<!--
--><code>(...) {{cc|unscheduled code}}<br><!--
--><sqf>
-->[_var1, _var2] [[spawn]] TAG_fnc_MyFunction;<br><!--
/* ... */ // unscheduled code
-->(...) {{cc|other unscheduled code}}</code>
[_var1, _var2] spawn TAG_fnc_MyFunction;
{{ Informative | See also [[Scheduler#Where code starts unscheduled|Where code starts unscheduled]]. }}
/* ... */ // other unscheduled code
</sqf>
{{ Feature | Informative | See also [[Scheduler#Where code starts unscheduled|Where code starts unscheduled]]. }}
|}
|}


Line 164: Line 172:
== Performance Diagnostic tools ==
== Performance Diagnostic tools ==


=== Server commands ===
=== Server Commands ===


* [[Multiplayer Server Commands#Commands|#monitor]] 5
* [[Multiplayer Server Commands#Commands|#monitor]] 5
Line 172: Line 180:


=== Diagnostic commands ===
=== Diagnostic commands ===
 
* [[:Category:Arma_3:_Scripting_Commands:_Diagnostic_Branch|Diag. commands only available in Diagnostic Branch]]
{| class="bikitable"
* [[:Category:Command_Group:_Diagnostic|Diag. command available in all builds]]
! All builds !! Diagnostic build only
|- style="vertical-align: top"
 
| style="padding: 1em 2em 1em 1em" |
* [[diag_activeMissionFSMs]]
* [[diag_activeScripts]]
* [[diag_activeSQFScripts]]
* [[diag_activeSQSScripts]]
* [[diag_codePerformance]]
* [[diag_deltaTime]]
* [[diag_fps]]
* [[diag_fpsMin]]
* [[diag_frameNo]]
* [[diag_log]]
* [[diag_tickTime]]
 
| style="padding: 1em 2em 1em 1em" |
* [[diag_captureFrame]]
* [[diag_captureFrameToFile]]
* [[diag_captureSlowFrame]]
* [[diag_drawMode]]
* [[diag_enable]]
* [[diag_enabled]]
* [[diag_lightNewLoad]]
* [[diag_list]]
* [[diag_logSlowFrame]]
* [[diag_mergeConfigFile]]
* [[diag_recordTurretLimits]]
* [[diag_resetShapes]]
* [[diag_setLightNew]]
* [[diag_toggle]]
|}




== See also ==
== See Also ==


* [[Multiplayer Scripting]]
* [[Multiplayer Scripting]]
Line 214: Line 190:
* [[Code Best Practices]]
* [[Code Best Practices]]
* [[Performance Profiling]]
* [[Performance Profiling]]
* [[User:Dedmen|Dedmen]]'s [[ArmaScriptProfiler]] ([https://forums.bohemia.net/forums/topic/211626-arma-script-profiler/ forum post])
* [[User:Dedmen|Dedmen]]'s [[ArmaScriptProfiler]] ({{Link|link= https://forums.bohemia.net/forums/topic/211626-arma-script-profiler/|text= forum post}})




[[Category: Scripting Topics]]
[[Category:Arma Scripting Tutorials]]

Latest revision as of 10:38, 6 May 2024

This page is about Mission Optimisation. For scripting optimisation, see Code Optimisation.

This article will try to be a general guide about improving your mission's performance.
As usual, moderation is the key; do not expect to find on this page a magical solution that makes it possible to run thousands of AI at 240 FPS. Everything comes at a cost, the tweaks here will simply allow you to locate issues and calibrate your mission properly.


Before Anything

Before optimising anything, make sure you do not have any performance issue running the game itself:

  • Read Arma 3: Performance Optimisation
  • Open the editor, place a unit in the area you like and test your computer.
    • You can get current FPS in Arma 3 by going into video options or using diag_fps
    • Steam allows you to display FPS in a screen corner, in Settings > In game > FPS Counter
  • Use (unofficial) Performance Guides to get better performances:
  • Play your mission in singleplayer. If your mission runs fine, its network messages might very well be the issue. See Multiplayer Scripting for good practice tips.
  • Usual bottlenecks:
    • Lower your graphical settings (resolution, textures). If you get way better performances, at least your GPU limits you.
    • If the game keeps having low FPS when running @ 1024×768/low textures then your CPU is most likely the issue. Mission scripts may be performance-hogging too.
Please note that view distance (among other settings) impacts both GPU and CPU!
View distance can be separately set for each clients independently from the server's value through scripting.
This can make or break performance for the client.


Creating your Mission


Performance Impact Table

means a heavy impact on performance
means an average impact
means little to no performance impact.
Topic CPU GPU Net-
work
Solution

AI unit quantity

  • Use Agents whenever possible
  • The more units there are, the more network updates there will be - hence the impact on both CPU and network.
  • If a client has a low-end machine, they shouldn't lead a group of many AIs as these would then be locally computed.
  • Arma 3: Dynamic Simulation allows you to freeze AI that are distant from players. Many distance settings should be set according to the mission.
If you own more than one average computer, you could consider Headless client to offload AI from the server.

Object quantity

The less objects, the more FPS you will have.
Only the on-screen objects will strongly impact GPU.

General script mistakes

Having too many scripts running is a cause for severe performance issues and execution delays in singleplayer as well as multiplayer.

High-frequency scripts

Checking a condition too often is usually a source of poor performance. Does your code execution need to be frame-perfect, or can you afford a delay of a few seconds?
  • A while-loop checking without a minimum loop-sleep time is usually a sign of bad conception.
    while { true } // bad if you don't know what you are doing while { alive player } // better while { sleep 1 ; alive player } // perfect
  • By default, Triggers check their set condition every 0.5 second. If a large area is covered or condition code is too complex, this can become an issue; the triggers should then be converted to scripts if possible. Since Arma 3 logo black.png2.00 it is possible to change trigger intervals, either via trigger attributes in 3DEN, or via the scripting command setTriggerInterval.
  • Triggers can be made Server-Side only to save clients' resources.
All of the mission-related calculation (objectives, completion distance, etc.) must be done server-side. Local effects should be calculated client-side.

High-frequency network messages

  • Use publicVariable wisely; for specific cases, consider publicVariableServer / publicVariableClient
  • Creating units/vehicles globally implies a network synchronisation, keep them to a minimum / at one-point in the mission.
  • Keep global effect commands to a minimum:
    • e.g a setPos will synchronise the unit position to every client, a good practice is to use these commands punctually. If you need a frequent "set position" you may want to look at attachTo depending on your usage.
    • global marker commands always send all the marker's information. If you are creating/updating many markers e.g server-side, edit them with local commands, except the last one (that will be global) to send the whole marker's status over the network, once.
  • Lower client's view distance in order to lessen its object position update requests

Unscheduled code

Unscheduled code can have a high impact on the framerate, as such code is not subject to the scheduler's management (as its name suggests) and will run without limitation. Cyclic unscheduled low-performance code can make the game unplayable, up to freezing it.
  • As only time-critical scripts should run unscheduled, spawn any other code from unscheduled environment once you have the required results:
    /* ... */ // unscheduled code [_var1, _var2] spawn TAG_fnc_MyFunction; /* ... */ // other unscheduled code


What else?

If you have applied all these recommendations and your mission still doesn't run well in multiplayer (but does in singleplayer), it might be caused by mods that you are running which could be badly, or not at all, optimised.

If you want to be sure, run the same mission with and without mods. If you have a big difference in performance, look no further.


Performance Diagnostic tools

Server Commands

  • #monitor 5
    • Shows performance information of the server. Interval 0 means to stop monitoring.
  • #monitords 5
    • Shows performance information in the dedicated server console. Interval 0 means to stop monitoring. (since Arma 3 v1.64)

Diagnostic commands


See Also