</head> <body> <h1>Script Performance</h1> <p>To maximize performance, avoid using SetFormat (except the <a href="../lib/SetFormat.htm#Fast">fast mode</a>) and include the following lines near the top of each script:</p> <pre><a href="../lib/_NoEnv.htm">#NoEnv</a> <a href="../lib/SetBatchLines.htm">SetBatchLines -1</a> <a href="../lib/ListLines.htm">ListLines Off</a></pre> <p>In addition, the following commands may also affect performance depending on the nature of the script: <a href="../lib/SendMode.htm">SendMode</a>, <a href="../lib/SetKeyDelay.htm">SetKeyDelay</a>, <a href="../lib/SetMouseDelay.htm">SetMouseDelay</a>, <a href="../lib/SetWinDelay.htm">SetWinDelay</a>, <a href="../lib/SetControlDelay.htm">SetControlDelay</a>, and <a href="../lib/SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a>.</p> <h2 id="Built-in_Performance_Features">Built-in Performance Features</h2> <p>Each script is semi-compiled while it is being loaded and syntax-checked. In addition to reducing the memory consumed by the script, this also greatly improves runtime performance.</p> <p>Here are the technical details of the optimization process (semi-compiling):</p> <ul> <li>Input and output variables (when their names don't contain references to other variables) and <a href="../lib/GroupAdd.htm">group</a> names are resolved to memory addresses.</li> <li><a href="../lib/Loop.htm">Loops</a>, <a href="../lib/Block.htm">blocks</a>, <a href="../lib/IfExpression.htm">IFs (expression)</a>, <a href="../lib/IfEqual.htm">IFs (legacy)</a>, and <a href="../lib/Else.htm">ELSEs</a> are given the memory addresses of their related jump-points in the script.</li> <li>The destination of each <a href="../Hotkeys.htm">Hotkey</a>,<a href="../lib/Gosub.htm"> Gosub</a>, and <a href="../lib/Goto.htm">Goto</a> is resolved to a memory address unless it is a variable.</li> <li>Each command name is replaced by an address in a jump table.</li> <li>Each line is pre-parsed into a list of parameters, and each parameter is pre-parsed into a list of <a href="../Variables.htm">variables</a> (if any).</li> <li>Each <a href="../Variables.htm#Expressions">expression</a> is tokenized and converted from infix to postfix.</li> <li>Each reference to a <a href="../Variables.htm">variable</a> or <a href="../Functions.htm">function</a> is resolved to a memory address.</li> <li>Literal integers in expressions and math/comparison commands are replaced with binary integers.</li> </ul> <p>In addition, during script execution, binary numbers are cached in variables to avoid conversions to/from strings. See <a href="../lib/SetFormat.htm#Fast">SetFormat</a> for details.</p> </body> </html>