Optimizing - ItsDeltin/Overwatch-Script-To-Workshop GitHub Wiki
Optimizing
Element count
Overwatch has an element count of 32,000. Each action, condition, and rule will add elements. If the ostw.codelens.elementCount
setting is set to true in vscode, the amount of elements a rule generates is shown above the rule. The status bar of vscode will show the total amount of elements used in the project (marked by the red arrow).
Note this screenshot was taken when the element count was only 20,000.
;
How elements are counted
Each rule, condition, and action cost 1 element.
Any values directly in the action or condition (0 depth) are free, with the exception of numbers and strings which cost 2 elements.
Any sub values (values with a depth of 1 or greater) cost an additional 2 elements. This includes workshop constants like buttons, colors, etc. Numbers and strings cost 4 elements.
The easiest way to optimize is to enable the ostw.optimizeOutput
setting in vscode. This will automatically reduce the element count. Optimizations include, but not limited to:
- Operators such as
Add
Subtract
, etc. are all calculated if the values are constant. - Vectors are converted to their workshop value equivalents (
up
,down
,left
,right
,forward
,backward
). This will save 12-14 elements. Value In Array
is converted toFirst Of
if the index is 0. This means you don't have to useFirstOf()
if you would rather use[0]
. This will save 4 elements.
Every time a function is called, its actions are inserted into the action-set. If a function is called multiple times, you should consider changing it to a subroutine.