Home .NET Meet RyuJIT: the new JIT compiler for .NET

Meet RyuJIT: the new JIT compiler for .NET

by admin

The world is moving towards 64-bit computing, despite the fact that as a result programs do not always work faster or more efficiently compared to 32-bit ones. Many 32-bit programs, for various reasons, can run faster than 64-bit programs. One such example is the 64-bit JIT compiler of the .NET framework. It does a lot of work to make your program work very fast, but, alas, it is not as fast as you’d like it to be. This is what we are going to fix. We present a new generation x64 JIT-compiler capable of compiling 64-bit .NET code twice as fast.

Let’s talk about x64

It seems that 32 bit x86 computers have been around for a long time. It is a great architecture which has one big problem: the address space of 32-bit pointers is limited to 4 GB. 64-bit computers with their extended pointers can address an almost limitless amount of data. When the first x64 version of Windows came out, RAM was relatively expensive, so 64-bit machines were mostly used as servers. Now x64 architecture is mainstream and computers typically ship with at least 4GB of RAM. Even some smartphones have switched to 64-bit processors despite having only 1 GB of RAM.
NET x64 JIT was designed to produce the most efficient code during the execution of long running processes running on the server. This is in contrast to .NET x86 JIT, which is optimized for the fastest compilation of IL code to machine code, allowing programs to run quickly. Optimizing code efficiency is often justified for server-side applications. But "server applications" also include web applications, one of the requirements for which is the fastest startup. The 64-bit JIT in current versions of .NET can rarely boast fast IL code compilation, forcing many to use other technologies such as NGen or background JIT.

RyuJIT rushes to the rescue!

RyuWHAT? The .NET Code Generation team is now working on a brand new x64 compiler with the working name RyuJIT. It runs twice as fast as the current version. It means that the launch time of programs compiled by it is reduced by about 30% (the time spent on JIT compilation is only a part of the application execution process, so just because JIT runs twice as fast does not mean that the application should also speed up in the same way). In addition, the new JIT still produces the highest performance machine code possible.
The graph below shows how much faster RyuJIT is than the current JIT64:
Meet RyuJIT: the new JIT compiler for .NET
Obviously, all the examples worked faster with the new JIT. You probably noticed that the second example (RFC822 e-mail RegEx) literally went over the edge of the graph. This is because regular expressions work particularly badly on JIT64. Compiling this example with the JIT64 compiler took 60 seconds and took 1.4 GB of memory. In RyuJIT’s case, it only took 1.8 seconds and 199 MB.
The Paint.NET example came out more normal. The application ran on the test machine was reduced from 2.3 seconds to 1.8 seconds. The compilation time was reduced from 1510ms to 970ms. I think it is clear that fast startup with minimal memory usage makes our world a better place.

And for dessert…

RyuJIT’s improved performance and reduced resource usage is great, of course, but it’s not the most exciting thing about it. When JIT64 was first developed, we decided to take the command optimization basis from the C++ compiler instead of the then existing 32-bit JIT compiler, which was better optimized for dynamic compilation scenarios. Most 64-bit computers were used as servers at the time, so it was important to focus on the quality of the compiled code instead of improving the performance of the compiler itself. And as a result, the .NET CodeGen team had to maintain code for two different compilers. Adding features and fixing bugs in two places slowed down the introduction of innovations. And the addition of the ARM architecture and MDIL for Windows Phone 8.0 in recent years has made this work even harder.
RyuJIT is based on the x86 JIT code base. So far, it only works for the 64-bit architecture. This upgraded compiler will later become the basis for all our JIT compilers : x86, ARM, MDIL and possibly something else. The common code base means that .NET applications will work as similarly as possible on different platforms, to put it simply, the bugs will be the same on different architectures. However, it also means that we will be able to implement new technologies much faster.

What does it take to try it?

The CTP version of RyuJIT is available and you can try it right now in your test environment. There is no support for production yet.
Download the RyuJIT installer is available right now, but it only works on 64-bit versions of Windows 8.1 and Windows Server 2012 R2. Note that RyuJIT doesn’t make any changes to NGen on your system – we wanted to keep the installation clean. Also, after enabling RyuJIT, while writing code, "Edit Continue" in VS will stop working for x64.
After installation, there are two ways to enable RyuJIT. If you only want to enable it for one specific application, add an environment variable " COMPLUS_AltJit=* ". If you want to enable it for all applications, you have to define the registry key " HKLMSOFTWAREMicrosoft.NETFrameworkAltJit " with the line "*". Both these methods force the 64-bit CLR to use RyuJIT instead of JIT64. In addition, both of these methods are reversible – installing RyuJIT doesn’t change anything on your computer (except the placement of files in the compiler directory).
Source : NET Framework Blog
Teamblog .NET Code Generation

You may also like