Script speed and #LPC
“Is goto faster than gosub?” comes up often. The answer lies in how EasyUO runs a script.
Cycles
Section titled “Cycles”A script runs in cycles. In each cycle it runs #LPC lines (10 by default) and then
pauses 50 ms, which leaves the computer to the UO client and everything else. That makes about 20 cycles, or
200 lines, a second.
; what EasyUO does, in pseudo-codestart: run #LPC lines of the script pause 50 msgoto startA comment, a goto and a gosub each count as one line. Running a line takes almost no time compared with the
50 ms pause, so which command a line holds hardly matters: goto is not faster than gosub, and removing
comments only saves lines, not real work. Some commands, such as key,
click, target and wait, wait on purpose and
take as long as they take.
Making scripts faster
Section titled “Making scripts faster”Raise #LPC where a script does a lot of quick work, and lower it again afterwards:
set #LPC 1000set %sum 0for %i 1 1000 ; a lot of quick lines set %sum %sum + %iset #LPC 10display ok The sum is %sumhaltA high #LPC lets the script take more of the computer’s time. That is fine for bursts of calculation, menu
building or text work. For commands that make the client do work, such as finditem,
a high value only uses more CPU without making the game respond faster.
Measuring
Section titled “Measuring”To compare commands, take the 50 ms pause out of the measurement by setting a very high #LPC, and time many
repetitions with #SysTime:
set #LPC 100000000set %start #SysTimefor %i 1 100000 set %x 3set %took #SysTime - %startset #LPC 10display ok 100000 sets took %took mshaltIn the original EasyUO, a huge #LPC froze the EasyUO window until the loop ended. In EasyUO Reforged each
script runs on its own thread and gives way briefly every 1024 lines, so the window stays usable and Stop
still works.
Based on Cheffe’s tutorial on execution speed from the EasyUO wiki.
Based on the EasyUO wiki, edited for EasyUO Reforged. This text is available under the GNU Free Documentation License 1.2.