Memory. It can be cached by ngen.exe to work. It generates a version of the .ni.dll assembly, which contains machine code and is stored in the GAC. Which automatically loads after that, bypassing the JIT step.
But this has little to do with why your program runs faster the second time. The first time you have a so-called cold start. Which is completely dominated by the time spent searching for DLLs on the hard drive. The second time you started a warm start, the DLLs are already available in the file system cache.
Drives are slow. SSD is an obvious fix.
Fwiw: This is not an issue that is exclusive to managed code. Large unmanaged programs with lots of DLLs have it too. Two canonical examples found on most development machines are Microsoft Office and Acrobat Reader. They are cheating. During installation, they put the "optimizer" in the "Run the registry key" section or the "Startup" folder. All these optimizers do is download all the DLL files that the main program uses and then exit. This means that the file system cache, when the user subsequently uses the program, starts quickly, as his hot start is fast.
Personally, I find this extremely annoying. Because what they really do slows down any other program that I might want to start after I log in. It is rarely Office or Acrobat. I do this to remove these optimizers, if necessary, when the update is exploded.
You can also use this trick, but use it responsibly.
Hans Passant Jul 21 2018-10-21T00: 00-07
source share