|
Top Tank
Wasted Jack
Join date: 5 Dec 2005
Posts: 12
|
09-28-2008 08:32
In the beginning there was LSL.
Due to a shortcoming in the original LSL implementation, adding elements to lists in a simple, straightforward way used to be extremely wasteful in memory.
myList += [NEW_ELEMENT]; // Simple but wasteful
Years ago, someone came up with a trick that significantly improves the memory footprint of adding elements to lists. The trick was to do it as follows:
myList = (myList = []) + myList + [NEW_ELEMENT]; // Complex but more efficient
The complex method allowed adding many more elements to lists before running out of memory. In a test with NEW_ELEMENT being the string "Hello, World!", using the complex method repeatedly provided a 220% capacity increase (620 elements vs. 280 elements). Unfortunately, it was also slower - each addition to the list took about 40% more time to complete when the complex method was used.
Enter Mono. With Mono on the main grid, I was curious to see whether there is still a justification to using the complex method. I ran the same test with Mono. The results were pleasantly surprising. The simple method managed to add 7540 elements before running out of memory, and took 106.52 seconds to do so. The complex method was still slower but did not have the memory capacity benefit anymore. It took 122.29 seconds to add the same 7540 elements before running out of memory.
Conclusion: With Mono, it is better to use the simple, straightforward method when adding elements to lists.
Comments welcome!
|
|
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
|
09-28-2008 08:49
Admittedly, your test shows that the complex method is slower.. but it is "negligibly slower".
You have to do a little division to see what I mean.
Short method: 106.52 seconds.. divided by 7540... an average 0.014091511936339522546419098143236 seconds per entry.
14.1 milliseconds
Long method: 122.29 seconds... divided by 7540... 0.016218832891246684350132625994695
16.2 milliseconds
While it's true, that this obviously "adds up" when you're compiling lists of 7000+ entries, We're only talking about a a difference of about 2-milliseconds per process.. or a cumulative 15.77 seconds, out of almost 2 minutes. The fact is that probably 99% of all scripting applications CURRENTLY on the grid, could have no hope of doing that kind of speed.
Most sluggishness in SL scripts is NOT related to processing time, but to the artificial throttles placed on various functions like sensors, instant messages, prim param changes, and the like. It's definitely cool that mono can hold more.. and can hold more faster than lsl2... it would be interesting to see the time it took to overflow those lists in lsl2.
Until these artificial throttles are raised or removed, the speed increases of mono will remain largely acedemic, benefitting only a very small percentage of power-users.
_____________________
 ● Inworld Store: http://slurl.eclectic-randomness.com ● Website: http://www.eclectic-randomness.com ● Twitter: @WinterVentura
|
|
Top Tank
Wasted Jack
Join date: 5 Dec 2005
Posts: 12
|
09-28-2008 09:02
With LSL2 (pre Mono), using the simple method would add 280 elements in 10.28 seconds before running out of memory, while the complex method managed to add 620 elements in 31.15 seconds before crashing.
This translates to 36ms per operation for the simple method versus 50ms per operation when using the complex method.
In LSL2, I believe the benefit in memory capacity would in most cases justify the additional execution time.
|
|
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
|
09-29-2008 07:31
wohoo!
had a hard time remembering the voodoo formula for that anyway :X
_____________________
Why Johnny Can't Rotate: http://forums.secondlife.com/showthread.php?t=94705
|