How to preload .net assemblies

In my work, we develop various applications using the .net framework 4. All applications use common assemblies that we developed, for example, the data layer in data.dll. These applications are located on a network drive and run directly from there.

Most large applications require time, for example, 4-5 seconds, to start for the first time (cold start). Subsequent launches are much faster, almost instantly. I donโ€™t think this is connected to the network, since the largest build is about 900 KB, and we use the Gigabit network.

I would like to create a service that starts when the computer starts and loads all .net assemblies in a specific directory. I hope that when the user launches the program, all necessary assemblies will already be loaded and "JITed", so the launch should be faster.

I know how to create a service, but I would like to know if this can work, because my understanding of the CLR is quite limited ... Also, will work on the assembly Assembly.LoadFrom (fileName) to preload the assemblies? If I do not start any programs for a while, do they remain loaded or do they unload after a while? What happens if I change an already loaded assembly?

Basically, I would like to do something like OpenOffice Quick startter , but for our own application platform.

Thanks everyone !!!

--- EDIT ---
This is interesting ... seems to be going the right way, but not sure if I understand everything ...

+4
source share
4 answers

You already know that compiling JIT is not a problem, which will also slow down the second run. All you have to do is get the DLLs in the file system cache. So when you run the program later, it will use a copy of this DLL from the cache instead of digging through a network-connected drive to find it. This is what takes time. Office Quick Start uses the same trick. Not sure who will win if all these preloaded things no longer fit.

Just create a Winforms application, so you wonโ€™t get a window and call Assembly.Load () to load the assemblies, File.ReadAllBytes () so that all the content is in the cache. Place a shortcut for this program in the Startup folder. This assembly that you mentioned is large enough to get a boost in a warm start from Ngen.exe. However, this must be done on each individual workstation.

+2
source

You can pre-create assemblies programmatically using the technique described in the following article: Pre-compile (before JIT) your assembly on the fly or trigger a JIT compilation trigger ahead of time.

However, I do not think that their blow in one process will affect another (not sure about this). One possible solution is to run the application on a computer with command line parameters indicating that it should only stop assemblies and do nothing. When the user starts the application, he will inform that the already running process has launched its functions by default.

+1
source

You have several options. Assuming generic assemblies have strong names, they can be placed in a custom global assembly cache (GAC). If these assemblies are stable, you may have your own code generated with ngen.exe that will give you the "pre-JIT'd" you need. Google GAC and ngen for more information.

Edit after updating the question:

Downloading assemblies in the form in which you are looking is not necessarily the most efficient way - these assemblies will live in your service memory as long as the service is nearby, and this may or may not be a burden for the client machine.

I believe that the combination of GAC'ing and ngen'ing of your assemblies is the best bet, and both of these steps can be automated (provided that the service is run with the appropriate permissions) by extracting the assemblies and making external calls to gacutil.exe and ngen. exe using the System.Diagnostics.Process class.

MSDN page for ngen.exe

MSDN page for gacutil.exe

MSDN Page for Process Class

0
source

You want NGEN , which precompiles assemblies for you. I think the problem you are about to have is a build from the network and potentially downloadable for different processor architectures. NGEN should be run on the destination computer because it compiles and optimizes for the specific architecture used by the computer.

What you might think is to give strong build names and install them in the GAC on each computer.

I donโ€™t think that the approach you are considering will work, I think you are going to load them into the service process, and as soon as they are released, they will be cleaned by the system and the final result will not increase speed.

0
source

All Articles