Math/implicit casts have poor performance under LSL-Luau
Frionil Fang
The Luau VM seems to have generally worse math performance regardless of the language, though that may just be inherent to the VM and absolute number crunching speed is not of prime importance to most scripts (though it is for some of mine, sadly... the better data structure handling performance will probably make up for it even there, though). What however is curiously poor is any kind of implicit casting under LSL-Luau, to the level of seeming like a bug.
Simple test script: compile as LSL-Luau.
default
{
touch_start(integer _)
{
integer i;
integer a;
llResetTime();
for(i = 0; i < 1000000; ++i) {
a += 1;
}
llOwnerSay((string)llGetTime());
}
}
This should run in roughly ~9-10 seconds on touch.
Now, change the type of the variable a from integer to float, resulting in it having to do an implicit cast during the addition (the second addend is still an integer), and it will instead run in ~26 seconds.
The same effect can be observed for other situations with implicit casting (integer a, multiply by float; float a, multiply by integer), resulting much slower performance.
For comparison, the same script compiled under LSL-Mono will run in roughly ~3-4 seconds, slightly varying between float/integer but with little implicit-cast difference.
Log In
Kristy Aurelia
Maybe Lua does the Python thing, where everything is immutable, so
a += 1
actually creates a new variable.Or, try equivalent lua code and compare performance when
i
and a
do and do not have the local
keyword