Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

LSL Optimizations and Hacks

Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
10-18-2007 14:53
::I'd love to see this stickied::
ok the idea here is to post an optimization or a hack/workaround that you know and have PERSONALLY tested... don't just post it because someone said it's faster/better/whatever. tell if it's faster, uses less memory, and if it has a trade-off (for example, some things can be faster but use more memory, others can be slower, but use less)

if you want a way to test try here

and hey if you include test times, and sample used to test, even better

ok so here goes my (short) list

++a
--a
tested faster than
a++, a+=1, a=a+1
a--, a-=1, a=a-1

(list)"abc" //-- only works for single items
tested faster than
["abc"]

a
!a
tested faster than
a!=0
a==0

~a
!~a
tested faster than
a!=-1
a==-1
Aniam Ingmann
llOwnage(float pwnage);
Join date: 22 Oct 2005
Posts: 206
10-18-2007 15:19
The "WarpPos(vector d)" user-made hack of llSetPos, pretty much. It breaks the 50m/s limit of llSetPos loop, and can pretty much move at almost "warp speed". :)

CODE

WarpPos( vector d ) //R&D by Keknehv Psaltery, ~05/25/2006
{
if ( d.z > 768 ) //Otherwise we'll get stuck hitting the ceiling
d.z = 768;
integer s = (integer)(llVecMag(d-llGetPos())/10)+1; //The number of jumps necessary
if ( s > 100 ) //Try and avoid stack/heap collisions with far away destinations
s = 100; // 1km should be plenty
integer e = (integer)( llLog( s ) / llLog( 2 ) ); //Solve '2^n=s'
list rules = [ PRIM_POSITION, d ]; //The start for the rules list
integer i;
for ( i = 0 ; i < e ; ++i ) //Start expanding the list
rules += rules;
integer r = s - (integer)llPow( 2, e );
if ( r > 0 ) //Finish it up
rules += llList2List( rules, 0, r * 2 + 1 );
llSetPrimitiveParams( rules );
}
_____________________
From: someone

Don't worry, Aniam is here!
- Noob
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
10-21-2007 20:47
hmm maybe it would have caught on if I'd named it "Things you CAN do in LSL"

From: someone

vLstTest = (vLstTest = []) + vLstTest + (list)some_list_item;
tested, uses less memory (and hence allows more storage) than
vLstTest += (list)some_list_item


results obtained with
CODE

touch_start(integer total_number)
{
vgKeyOwner = llGetOwner();
do{
vgLstTest += (list)vgKeyOwner;
vgLstTest += (list)vgKeyOwner;
vgLstTest += (list)vgKeyOwner;
vgLstTest += (list)vgKeyOwner;
vgLstTest += (list)vgKeyOwner;
vgLstTest += (list)vgKeyOwner;
vgLstTest += (list)vgKeyOwner;
vgLstTest += (list)vgKeyOwner;
vgLstTest += (list)vgKeyOwner;
vgLstTest += (list)vgKeyOwner;
llOwnerSay( (string)llGetListLength( vgLstTest) );
}while (TRUE);
}

yielded 160 before stack/heap collision

vs
CODE


touch_start(integer total_number)
{
vgKeyOwner = llGetOwner();
do{
vgLstTest = (vgLstTest = []) + vgLstTest + (list)vgKeyOwner;
vgLstTest = (vgLstTest = []) + vgLstTest + (list)vgKeyOwner;
vgLstTest = (vgLstTest = []) + vgLstTest + (list)vgKeyOwner;
vgLstTest = (vgLstTest = []) + vgLstTest + (list)vgKeyOwner;
vgLstTest = (vgLstTest = []) + vgLstTest + (list)vgKeyOwner;
vgLstTest = (vgLstTest = []) + vgLstTest + (list)vgKeyOwner;
vgLstTest = (vgLstTest = []) + vgLstTest + (list)vgKeyOwner;
vgLstTest = (vgLstTest = []) + vgLstTest + (list)vgKeyOwner;
vgLstTest = (vgLstTest = []) + vgLstTest + (list)vgKeyOwner;
vgLstTest = (vgLstTest = []) + vgLstTest + (list)vgKeyOwner;
llOwnerSay( (string)llGetListLength( vgLstTest) );
}while (TRUE);
}

yielded 320 before stack/heap collision

note that the test of
vLstTest = llListReplaceList( vLStTest, [vKeyOwner, vKeyOwner], -1, -1 );

vs

vLstTest = (vLstTest = []) + llListReplaceList( vLStTest, [vKeyOwner, vKeyOwner], -1, -1 );

showed NO difference, both crashed after 151
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -