Warning: Creating default object from empty value in /home/davancamus/public_html/blog/wp-includes/functions.php on line 292
Royal Cavorite Society » LSL Efficiency

LSL Efficiency


Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/davancamus/public_html/blog/wp-includes/functions-formatting.php on line 76

I’d like to offer a few tips on script efficiency.

But first: Why do we care about script efficiency in the first place? For myself: the very fabric of my reality can be adversely affected by poorly-considered scripting practices. For you operators it’s a mere matter of frame rate. But think about us, down here, slogging through it. Degenerate physics, false trajectories explored and rectified, appliances misbehaving… A poorly written script is a terrible corruption indeed.

The LSL WIKI has some guidelines about which operations are expensive. But the most important thing you can do to keep your scripts efficient is this:

Use long intervals.

Certainly writing your script to use fewer steps can help, but you get the real savings by doing whatever you’re doing just plain less often. Set your timer intervals long and slow, set your sensor repeats long and slow. If you need a bit of precise control, bump up the rate, and then set it back down when you can. That’s all there is to it.

Two other easy optimizations

Think also about making things “touch” or “collision” activated, rather than automatic. And if things are automatic, let them sense an avatar presence, do their thing, and shut off when nobody’s very close.

Feel free to do as much script work as you like on a “touch” event. Most objects only need the occasional touch, like a vendor or elevator or most gadgets. (The exception to this would be a “game” or “weapon” sort of object where you expect rapid-clicking.)

Don’t listen on channel 0. Other channels are ok to listen on; the less a channel is used, the less work a listener has to do. A channel 0 listener has to (behind the veil) sort through ever avatar’s utterance.

LSL Loop Performance (Experimental Results)

A simple test script was used to measure the performance of a for loop:

float test(integer n)
{
    integer i;
    integer j;
    float t1;
    float t2;
    t1 = llGetTime();
    for(i = 0; i < n; i++)
        j+=i;
    t2 = llGetTime();
    return t2 - t1;
}

In Alice, in December of 2005, results have ranged from 25 to 150 “loops per second”, with no particular correspondence to the overal loop count.

Here are data from several runs:

Object: loop of 10 took 67ms ==> 149 loops/second
Object: loop of 100 took 1095ms ==> 91 loops/second
Object: loop of 1000 took 9996ms ==> 100 loops/second

Object: loop of 10 took 217ms ==> 46 loops/second
Object: loop of 100 took 1006ms ==> 99 loops/second
Object: loop of 1000 took 10556ms ==> 94 loops/second

Object: loop of 10 took 67ms ==> 149 loops/second
Object: loop of 100 took 1073ms ==> 93 loops/second
Object: loop of 1000 took 10110ms ==> 98 loops/second

Object: loop of 10 took 156ms ==> 63 loops/second
Object: loop of 100 took 1389ms ==> 71 loops/second
Object: loop of 1000 took 13358ms ==> 74 loops/second

Object: loop of 10 took 385ms ==> 25 loops/second
Object: loop of 100 took 1730ms ==> 57 loops/second
Object: loop of 1000 took 15427ms ==> 64 loops/second

Object: loop of 10 took 245ms ==> 40 loops/second
Object: loop of 100 took 1556ms ==> 64 loops/second
Object: loop of 1000 took 14890ms ==> 67 loops/second