iliveisl

Mono and Bytecode Sharing

8 comments

Server version 1.24.3 in August of 2008, implemented Mono as an alternate way to compile and run LSL scripts. Mono is a free and open source implementation of Microsoft’s .NET and is sponsored by Novell. This is all pretty old news by now. But there is one feature in the implementation with Second Life that is worth talking about.  Bytecode sharing. 

So, what’s a bytecode?  And how do you share it?

The term ‘bytecode’ came into general usage when Sun Microsystems created Java.  But the concept is actually at least as old as 1966.  It was just called other things such as o-code, p-code and pseudo-code.  The idea behind all of these is that a compiler can translate a high level programming language into a hardware independent set of instructions that can either be translated into machine code or quickly interpreted at run time for a specific hardware platform.  This approach allowed compilers to be created that could be relatively easily ported to different hardware platforms or compiled code to be created that was independent of a specific hardware platform.  The hardware specific translator or interpreter would still have to be created for each hardware platform, but this was a far easier task than rewriting a compiler for each set of hardware to directly produce machine code for that hardware.

And now to the sharing part. The Second Life server will only load one copy of the compiled bytecode for a script, no matter how many times that script occurs in the sim. So, 10 instances of the script use the same amount of memory as one instance of the script, not counting the data. Only the program code portion of the script is shared. Each individual usage of the script gets its own data area. The requirement to support bytecode sharing is that the same script is not recompiled each time it is placed in a new object. For example, each time you want to reuse the same script, either copy the object with the script intact or drag the compiled script from your inventory into each object without recompiling it. If you recompile the script the sim can no longer tell that it is a duplicate copy.

In reality, this may be a small savings in memory. It is likely that in the 1,000s of scripts loaded in a sim, there may be a small percentage of duplication. And those that are duplicated may be small scripts like your fancy window tinting scripts. But, treating scripts carefully to support bytecode sharing is an easy thing to do and every little bit helps.

You may have scripts that differ only in the setting of just a few variables. Having to compile slightly different versions of the same script would prevent bytecode sharing in addition to making it a little harder to maintain changes to the script. In future blog entries, I plan to show several methods to allow scripts to obtain different configuration options so that the same script can be used to perform slightly different operations.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Written by Micheil Merlin

December 2nd, 2009 at 7:32 pm

Posted in second life

Tagged with

8 Responses to 'Mono and Bytecode Sharing'

Subscribe to comments with RSS or TrackBack to 'Mono and Bytecode Sharing'.

  1. wow! this is a positive step by Linden Lab and nice to see amid things like X Street messes

    i would think this is significant over the entire grid. thanks for a nice explanation +)

    Ener Hax

    2 Dec 09 at 10:07 pm

  2. I like it when Micheil talks all nerdy, don’t you?

  3. [...] I’d written a post on Mono and Bytecode Sharing. In that post, I mentioned that there were several ways that a script could be written to take [...]

  4. [...] | Reply Tags: scripts (3), second life (365) Continuing on a theme beginning with “Mono Bytecode Sharing“, followed by “Does your script need socks“, this is another post describing [...]

  5. [...] on a theme beginning with “Mono Bytecode Sharing“, followed by “Does your script need socks“, and then by “Put object description to good [...]

  6. [...] on a theme beginning with “Mono Bytecode Sharing“, followed by “Does your script need socks“, and then by “Put object description to good [...]

  7. [...] on a theme beginning with “Mono Bytecode Sharing“, followed by “Does your script need socks“, this is another post describing [...]

  8. [...] I’d written a post on Mono and Bytecode Sharing. In that post, I mentioned that there were several ways that a script could be written to take [...]

leave a reply - add your thoughts