Mission Optimisation: Difference between revisions
Lou Montana (talk | contribs) m (Text replacement - "Multiplayer framework" to "Arma 2: Multiplayer Framework") |
Lou Montana (talk | contribs) (Add marker management trick) |
||
Line 4: | Line 4: | ||
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 a magical solution that makes it possible to run thousands of AI at 144 FPS | 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. | ||
Line 45: | Line 45: | ||
== Performance impact table == | == Performance impact table == | ||
{{Informative| | {{Informative| | ||
: {{colorball|red|1.125}} means a heavy impact on performance<br> | : {{colorball|red|1.125}} means a heavy impact on performance<br> | ||
Line 104: | Line 105: | ||
** [[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; {{ | --><code>{ [[_x]] [[spawn]] _myCode; } [[forEach]] _units; {{cc|bad}}<br><!-- | ||
-->_units [[spawn]] _myCode; {{ | -->_units [[spawn]] _myCode; {{cc|good}}</code><!-- | ||
-->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.<br><!-- | ||
--><code>[[while]] { [[sleep]] 5; [[alive]] [[player]] } [[do]] { [[player]] [[execVM]] "myScript.sqf"; }; {{ | --><code>[[while]] { [[sleep]] 5; [[alive]] [[player]] } [[do]] { [[player]] [[execVM]] "myScript.sqf"; }; {{cc|bad}}<br><br><!-- | ||
-->[[private]] _myScript = [[compile]] [[preprocessFileLineNumbers]] "myScript.sqf";<br><!-- | -->[[private]] _myScript = [[compile]] [[preprocessFileLineNumbers]] "myScript.sqf";<br><!-- | ||
-->[[while]] { [[sleep]] 5; [[alive]] [[player]] } [[do]] { [[player]] [[spawn]] _myScript; }; {{ | -->[[while]] { [[sleep]] 5; [[alive]] [[player]] } [[do]] { [[player]] [[spawn]] _myScript; }; {{cc|good}}</code> | ||
|- | |- | ||
| | | | ||
Line 119: | Line 120: | ||
| 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]] } {{ | --><code>[[while]] { [[true]] } {{cc|bad if you don't know what you are doing}}<br><!-- | ||
-->[[while]] { [[alive]] [[player]] } {{ | -->[[while]] { [[alive]] [[player]] } {{cc|better}}<br><!-- | ||
-->[[while]] { [[sleep]] 1 ; [[alive]] [[player]] } {{ | -->[[while]] { [[sleep]] 1 ; [[alive]] [[player]] } {{cc|perfect}}</code> | ||
* [[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. | * [[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. | ||
* [[trigger|Triggers]] can be made '''Server-Side only''' to save clients' resources. | * [[trigger|Triggers]] can be made '''Server-Side only''' to save clients' resources. | ||
Line 134: | Line 135: | ||
* Use [[publicVariable]] wisely; for specific cases, consider [[publicVariableServer]] / [[publicVariableClient]] | * Use [[publicVariable]] wisely; for specific cases, consider [[publicVariableServer]] / [[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: 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. | * Keep [[:Category:Commands with global effects|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. | |||
** [[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. | |||
* Lower client's [[viewDistance|view distance]] in order to lessen its object position update requests | * Lower client's [[viewDistance|view distance]] in order to lessen its object position update requests | ||
|- | |- | ||
Line 144: | Line 147: | ||
| [[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>(...) {{ | --><code>(...) {{cc|unscheduled code}}<br><!-- | ||
-->[_var1, _var2] [[spawn]] TAG_fnc_MyFunction;<br><!-- | -->[_var1, _var2] [[spawn]] TAG_fnc_MyFunction;<br><!-- | ||
-->(...) {{ | -->(...) {{cc|other unscheduled code}}</code> | ||
{{ Informative | See also [[Scheduler#Where code starts unscheduled|Where code starts unscheduled]]. }} | {{ Informative | See also [[Scheduler#Where code starts unscheduled|Where code starts unscheduled]]. }} | ||
|} | |} |
Revision as of 13:26, 16 October 2020
Introduction
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 144 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:
- 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.
Creating your mission
- Be sure to create your scripts with the latest available commands and functions.
- In Arma 3 use remoteExec / remoteExecCall and DITCH BIS_fnc_MP FOR GOOD! See Arma 3 Remote Execution for more information.
- In Arma 2 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:
Performance impact table
Topic | CPU | GPU | Net- work |
Solution |
---|---|---|---|---|
AI unit quantity |
Template:colorball | Template:colorball | Template:colorball |
|
Object quantity |
Template:colorball | Template:colorball | Template:colorball | The less objects, the more FPS you will have.
|
General script mistakes |
Template:colorball | Template:colorball | Template:colorball | Having too many scripts running is a cause for severe performance issues and execution delays in singleplayer as well as multiplayer.
|
High-frequency scripts |
Template:colorball | Template:colorball | Template:colorball | 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?
|
High-frequency network messages |
Template:colorball | Template:colorball | Template:colorball |
|
Unscheduled code |
Template:colorball | Template:colorball | Template:colorball | 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. |
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
All builds | Diagnostic build only |
---|---|