Where is the .NET JIT-compiled code cached?

Memory. It can be cached, that’s the job of ngen.exe. It generates a .ni.dll version of the assembly, containing machine code and stored in the GAC. Which automatically gets loaded afterward, bypassing the JIT step.

But that has little to do with why your program starts faster the 2nd time. The 1st time you have a so-called “cold start”. Which is completely dominated by the time spent on finding the DLLs on the hard drive. The second time you’ve got a warm start, the DLLs are already available in the file system cache.

Disks are slow. An SSD is an obvious fix.

Fwiw: this is not a problem that’s exclusive to managed code. Large unmanaged programs with lots of DLLs have it too. Two canonical examples, present on most dev machines are Microsoft Office and Acrobat Reader. They cheat. When installed, they put an “optimizer” in the Run registry key or the Startup folder. All that these optimizers do is load all the DLLs that the main program uses, then exit. This primes the file system cache, when the user subsequently uses the program, it will start up quickly since its warm start is fast.

Personally, I find this extraordinarily annoying. Because what they really do is slow down any other program that I may want to start after logging in. Which is rarely Office or Acrobat. I make it a point to delete these optimizers, repeatedly if necessary when a blasted update puts it back.

You can use this trick too, but use it responsibly please.

Leave a Comment

Where is the .NET JIT-compiled code cached?

Memory. It can be cached, that’s the job of ngen.exe. It generates a .ni.dll version of the assembly, containing machine code and stored in the GAC. Which automatically gets loaded afterward, bypassing the JIT step.

But that has little to do with why your program starts faster the 2nd time. The 1st time you have a so-called “cold start”. Which is completely dominated by the time spent on finding the DLLs on the hard drive. The second time you’ve got a warm start, the DLLs are already available in the file system cache.

Disks are slow. An SSD is an obvious fix.

Fwiw: this is not a problem that’s exclusive to managed code. Large unmanaged programs with lots of DLLs have it too. Two canonical examples, present on most dev machines are Microsoft Office and Acrobat Reader. They cheat. When installed, they put an “optimizer” in the Run registry key or the Startup folder. All that these optimizers do is load all the DLLs that the main program uses, then exit. This primes the file system cache, when the user subsequently uses the program, it will start up quickly since its warm start is fast.

Personally, I find this extraordinarily annoying. Because what they really do is slow down any other program that I may want to start after logging in. Which is rarely Office or Acrobat. I make it a point to delete these optimizers, repeatedly if necessary when a blasted update puts it back.

You can use this trick too, but use it responsibly please.

Leave a Comment