Recently we talked about Unity and WebGL. In this post we briefly spoke about how scripting works in WebGL, using new technology called "Il2cpp". However, Il2cpp represents a lot more than just a scripting solution for WebGL; It's our own-performance. NET Runtime, to is rolled out in more platforms.
But before we delve to the future and let's talk about the present.
Scripting in Unity today
We leverage Mono (and WinRT on Windows Store Apps and Windows Phones) to bring the ease of use of C #, access to 3rd party L Ibraries, and near native performance to Unity. However, there is some challenges:
- C # Runtime performance still lags behind C + +
- Latest and greatest. NET language and runtime features is not supported Inunity ' s current version of Mono.
- With around platforms and architecture permutations, a large amount of effort are required for porting, maintaining, and Offering feature and quality parity.
- Garbage collection can cause pauses while running
These issues has remained in the front of our minds over the past few years as we sought to address them. Concurrently, investigations into supporting scripting for WebGL were occurring. As each progressed forward, these and paths converged into a single approach.
With the problem scope clear, experimentation on different ways to solve this were tried. Some of them were promising; Others were not. But ultimately we found a innovative solution and it proved to being the right-from-the-right.
That's the forward is il2cpp.
Il2cpp:the Quick and Dirty intro
Il2cpp consists of the Pieces:an Ahead of Time (AOT) compiler and a Virtual machine (VM).
These parts represent our own implementation of the Common Language Infrastructure, similar to. NET or Mono. It is compatible with the current scripting implementation in Unity.
Fundamentally, it differs from the current implementation in and the Il2cpp compiler converts assemblies into C + + source Code. It then leverages the standard platform C + + compilers to produce native binaries.
At runtime the This code was executed with additional services (like a GC, metadata, platform specific resources) that was Prov IDed by the Il2cpp VM.
The benefits of Il2cpp.
Let's talk on each one of the previously mentioned issues and how il2cpp addresses each of them.
Performance
Il2cpp seeks to provide the ease of use and productivity of C # with the performance of C + +.
It allows the current, productive scripting workflow to remain the same and giving an immediate performance boost. We ' ve seen 2x-3x performance improvements in some for our script-heavy benchmarks. This performance boost was due to a few reasons.
- C + + compilers and linkers provide a vast array of advanced optimisations previously unavailable.
- Static analysis was performed on your code for optimisation of both size and speed.
- Unity-focused optimisations to the Scripting runtime.
While Il2cpp was definitely still a work in progress, these early performance gains was indicative of great things to come.
. NET Upgrade
A very frequent request we get is to provide an upgraded runtime. While. NET have advanced through the past years, Unity currently supports. NET 2.0/3.5 ERA functionality for both the C # Compi Ler and the class libraries. Many users has requested access to newer features and both for their code as well as 3rd party libraries.
To complement Il2cpp, as it matures, we'll also be upgrading to recent versions of the Mono C # compiler, base class Libr Aries, and runtime for use in the editor (the editor would not be switch to il2cpp, for fast iteration during development). These things combined would bring a modern version of. NET to Unity.
It's also important to note that we're collaborating with Microsoft to bring and the future. NET functionality to Uni ty, ensuring compatibility and quality.
Portability and maintenance
While the this area is a internal issue for Unity to deal with, it also affects you. The Mono virtual machine has extensive amounts of platform and architecture specific code. When we bring Unity to a new platform, a large amount of our effort goes into porting and maintaining the Mono VM Platform. Features (and bugs) may exist on some platforms but not others. This affects the value which Unity strives to provide to you; Easy deployment of the same content to different platforms.
Il2cpp addresses these issues in a number of ways:
- All code generation are done to C + + rather than architecture specific machine code. The cost of porting and maintenance of architecture specific code generation are now more amortised.
- Feature Development and bug fixing proceed much faster. For us, days of mucking in architecture specific files is replaced by minutes of changing C + +. Features and bug fixes is immediately available for all platforms. In it's current state, il2cpp support is being ported to new platforms in short amount of time.
Additionally, platform or architecture specific compilers can be expected to optimise much better than a singular code gen Erator. This allows us to reuse all the effort that have gone into the C + + compilers, rather than reinventing it ourselves.
Garbage Collection
Il2cpp is not tied to any one specific garbage collector, instead interacting with a pluggable API. In it current iteration Il2cpp uses a upgraded version of LIBGC, even as we look at multiple options. Aside from just the GC itself, we is investigating reducing GC pressure by analysis do in the Il2cpp compiler.
While we don ' t has a lot more than share at the moment, the ongoing. We know this was important to many of the you, we'll continue working on it and keep your informed in the future blog posts. Unrelated to Il2cpp, but worth mentioning in the context of garbage collection, Unity 5 would see more and more allocation Free APIs.
What il2cpp are not
Il2cpp is not recreating the whole. NET or Mono toolchain. We'll continue to use the Mono C # compiler (and perhaps later, Roslyn). We'll continue to use the Mono class libraries. All currently supported features and 3rd party libraries which work with Mono AOT should continue to work with Il2cpp. We is only seeking to provide a replacement for the Mono VM and AOT compiler, and would keep on leveraging the wonderful M Ono Project.
When can I try Il2cpp?
By now we hope you is just as excited as we are to use il2cpp and wondering when you can get your hands on it! An early version of Il2cpp is available as part of the WebGL publishing in Unity 5.
Beyond WebGL, we is continuing development of il2cpp for other platforms. In fact, we already has working implementations on a number of our supported platforms. We expect to is rolling out at least one additional platform later the year. Our current plan was to have IOS being the next platform shipping with il2cpp support.
The planned upgrades of our Mono toolchain would follow after Il2cpp are available on more platforms and have matured.
One platform that would never be supported by Il2cpp is the Webplayer; This was due to security implications. And as noted earlier, the editor would remain to be using Mono.
Additionally, you can see the Il2cpp runtime in action today. As mentioned, the both WebGL demos we posted are il2cpp-powered.
What ' s next?
We is still hard in work on il2cpp:implementing new features, optimising code generation, fixing bugs, and supporting MO RE platforms. We'll keep posting more in-depth blogs as we make the progress and talk about it with your on theforums.
The Scripting Team.
The future of scripting in Unity