TechBubbles Microsoft Technology BLOG

Multicore JIT in .NET Framework 4.5

Multicore JIT is a great new feature in .NET Framework 4.5. Multicore JIT parallelizes the some of the JIT compilations that happens on the start of the application, Historically .NET FW has used the  Ngen Native Image Generator for parallelization. It works particularly well where this Ngen is installed. It has been with Silverlight 5 and ASP.NET. This post describes it’s features and how it works? Multicore JIT uses the parallelization to reduce the JIT compilation time during application startup. The fundamental problem with JIT compilation is , Jitting is normally a lazy operation, it Jits a method and do not know what next method is for jitting. So the solution is it has to remember something from previous run which is all the jitting that happened and now you have a good idea of what we are going to JIT this time around and we know what to JIT before we need it.

How it works?

It is actually two method calls for most of the applications , give me a folder which has a list of multicore-jit profiles and using profile optimization class, you can just say here is folder of all my multicore jit profiles and it just calls a method StartProfile. Once the startup is complete it saves a profile of methods to the disk at appropriate time. Basically you can call this as recording mode.

image

Next time when application runs the call will look for that profile and when it finds then it palys back which means it starts jitting all the methods that has saved for that profile.

image

Image reference from here

Using Multicore JIT

It is simple to use Multicore JIT, There is a class in .NET Framework named System.Runtime.ProfileOptimization which you can use to start profiling at the start of your application. The two methods that you can call are

 1: ProfileOptimization.SetProfileRoot(@"C:\StartupFolder");

 2: ProfileOptimization.StartProfile("Startup.Profile");

SetProfileRoot- it enables the profile optimization for the current application domain and sets the folder for saving profile optimization information. This method is ignored in single core computer

StartProfile– Starts the just in-time compilation for the methods that were previously recorded in a profile file.

You can have an application that can have multiple calls to StartProfile method. To take the full advantage of parallel compilation you can call the StartProfile at various stages in your application. ASP.NET Applications run hosted environment and you no need to write any code to turn on the Multicore JIT as it is automatically turned on.

Advantages

Applications now startup 50% faster , going from an average of around 155 seconds to just under 80 seconds. Note this feature is only available in .NET Framework 4.5  and this feature is enabled by default in ASP.NET applications and Silverlight applications. 50% reduction in startup gives a great relief for operational team just in case a service goes down then it will start back up twice as fast ! If you are unable to upgrade your application to .NET Framework 4.5 for some reason then you want to use this feature in .NET 4.0 then read this post

Multicore JIT compiles only the methods that you are going to use at runtime, off course you have to tell it once to the JIT first time about the methods that you are going to use at runtime.

image

This is definitely an easy solution for improving Application launch performance. ProfileOptimization requires multicore computer and it does not change the order in which the methods are  executed and moreover it does not run on the background process, suppose think if a method is compiled but never called then it is simply not used.

Reference: http://channel9.msdn.com/posts/NET-45-Multicore-JIT

Share this post :

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

Add Comment

TechBubbles Microsoft Technology BLOG

Follow me

Archives

Tag Cloud