Under The Grid: Mono in Second Life

Welcome to the seventh installment of "Under The Grid", an irregular look at the mechanics underneath Second Life. The last installment was back on Second Life Insider, last year – so don't worry that you've not seen it here on Massively before.

There's a lot of talk about Mono being rolled out in Second Life and a lot of general confusion, or excited misunderstanding about what it means. Mono isn't just a benefit for Second Life scripters its for everyone.

  • Firstly, what actually is Mono?

Mono is an open source version of a runtime software execution environment that you've probably referred to as Microsoft's .NET. If you don't know what a runtime software execution environment is, think Java. Mono is the bit that runs on a machine and makes code made for it run wherever Mono does, Windows systems, Mac systems, Linux and more.

Like Linden Lab's LSL language, there are three basic parts to the software. There's the source code (the script, if you prefer) that you or someone else wrote; there's the runtime engine (Mono) and there's the compiled code – a predigested form of your script that's ready to be run by the runtime engine. LSL has the same three basic pieces, but LSL scripts are translated into compiled code specifically for the LSL runtime engine.

The rollout essentially involves compiling LSL scripts into compiled code that the Mono runtime engine understands, instead of the LSL runtime engine. Mono doesn't understand predigested LSL, and the LSL engine doesn't understand Mono's compiled code either.

  • Why is it being rolled out in Second Life?

Mono is feature-rich, and is worked on and maintained by a large number of people – many more people than maintain Linden Lab's LSL scripting language execution environment. As a piece of software, it has few bugs and operates very fast. For a given number of seconds of CPU time, the Mono engine can do a whole lot more ... far more than the LSL engine can.

It isn't easy yet to compare how well real LSL scripts will run on Mono compared to running on the LSL engine – but preliminary results suggest between 70 and a couple hundred times better. Or, if you prefer to think of it another way, with 70 to a couple hundred times less load on the simulator. Less load means more simulator time to spend on other tasks, and that means less lag for sims that have heavy script loads. It also means significantly increased stability.

  • Lots of languages compile to Mono. Does this mean I can write Second Life scripts in other languages?

Essentially no. Or at least, not yet. Somewhere down the line that may happen, but that's not really what Linden Lab are interested in right now. Mono isn't, for the moment, about new features. It's about making existing features work better, smoother and with less trouble. Right now, most of the rest of the possibilities are pie-in-the-sky notions. Some of them doubtless will become realities later on.

Right now, it's all about compiling the existing LSL language to run on the Mono runtime engine without any changes or modifications. Nothing really new to know or languages to learn to get your LSL code running.

However the amount of memory available to scripts compiled for and running under Mono will be expanded to 64Kbytes, instead of the 16Kbytes presently available to LSL scripts.

Code won't be compiled in the viewer anymore and then sent to the server, either. Code is going to be compiled on grid-servers only – presumably to prevent malicious pre-compiled code from being injected into the Second Life grid.

  • What can go wrong?

Well, potentially everything – though Linden Lab's been doing a good job of fixing things up through the beta stage. One of the things that can go wrong involves scripts that are designed to go as fast as they can without checking the clock for timing (most often because doing things that fast was the only way to do them fast enough). Most likely these scripts will go too fast. Without checking the time, there's no way for them to know that they're performing many times faster than they used to. Some scripts will fall into this category and need to be reworked.

In the case of lost scripts (the infamous "Script missing from database" error, for example), there's no way to convert the original running script to Mono without the source code.

Scripts that aren't recompiled (or aren't able to be recompiled) to Mono under the new system just won't run on the Mono engine.

Another issue is bug-compatibility. Bug-compatibility is where you make a new implementation of something effectively function in exactly the same way as the old one – even when it's wrong. If 2+2 always gives the wrong answer in the old system, it has to give the same wrong answer in the new system – otherwise most everything written for the old system won't work properly with the new one.

Coupled with improved physics processing with Havok-4 simulator capacities should significantly improve, allowing higher workloads and potentially many more users per simulator (though none of those will help your viewer go any faster when having to render a lot of avatars and objects – that is what Windlight is for).

Recommended