Update – 10/2013: Check out Announcing the release of the .NET Framework for Windows Phone 8 from the .NET Team blog to learn more about how to use the .NET MDIL compiler.
While developing Windows Phone 7 or other .NET based applications on Visual Studio, building the project converted the code to an Intermediate Language (IL) which was later converted to binary, by a just-in-time (JIT) compiler, when it needed to be executed. The JIT compiler is invoked on a per-method basis as soon as the method in question is invoked. For subsequent calls to the method, the previous results are cached and reused, but only until the application is shut down! Then, all the compiled code is simply thrown away and the whole process starts over the next time the application is launched.
Advantages of this:
However, JIT compilation adds some overhead at execution time and the limitation of computational resources make things like parsing metadata, enforcing code validation, setting up dummy methods during load time (stubs) and compiling them into real code on the fly very expensive, costing seconds as opposed to milliseconds. Also, on smart phones the JIT compiler needs to work as fast as possible which means a less optimum code will be generated curbing the resulting additional benefits for the application. This lead to the relatively long application startup time on WP7.
Solution: Compile in the Cloud with MDIL
Before going into compiling in the cloud another solution that could be thought of, though it isn't as effective, is generating platform-specific machine code from the IL assemblies that then can be used without the need for a tool like the JIT compiler at all. However, generating those native images is slow even on powerful machines and images need to be regenerated when the original assembly or one of its dependencies is serviced. Simply moving the compilation of IL to native images, to the cloud would be a weak solution that introduces all sorts of new problems. Even if we used the power of the cloud to do the heavy lifting, we still would need to download that newly compiled image to our phones.
So, to solve this create yet another language that we can compile to and this language is MDIL - Machine Dependent Intermediate Language. MDIL is a format that somewhat resembles the final machine code, but it has placeholder tokens in all the places that usually would contain the hard-coded literals that potentially cause problems. This concept allows to have an "almost done" native image that can be finished in a final, very lean step directly on the phone. Once any dependencies change, that final step can easily be repeated in little time. The actual creation of the MDIL file (which is the heavy lifting in this process) can be performed in the cloud. When a client installs an app from the Phone Store, he already receives that prepared MDIL image from Microsoft's servers.
The result of this new feature can immediately be seen when you run an app on a Windows Phone 8 device and compare in particular the startup time to its behavior on Windows Phone 7 devices – improvements of 50% and more are absolutely possible.
Compile in the Cloud is one of these hidden gems in the set of new features of Windows Phone 8 that most likely won't be noticed and talked about a lot outside of a rather small, interested community.
How do you get your install to MDIL point though? Is this just a concept discussion, or something that actually exists at this point?
this actually exists today. Take a look at my original article that Deepti referenced at the bottom. The images and some of the text are taken from that article, where I explain more details.
I hope this helps,
On the desktop, why not just verify the dependencies havent changed and not throw away the cache?
I was wondering what does he mean by compiling in cloud and will it include more advanced heuristics for the JITer? . this really helps me .
<a href="www.craigcommunications.net/cloud-based-phone-system.asp">Cloud Phone Systems by Craig Comm</a>