Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speedup .NET assembly loading performance

We have a product with about 50 assemblies (DLL files) of which most are needed and loaded at startup of the main executable. The result is that even on a moderately fast machine, loading time of the assemblies and JIT'ing them takes between 2-3 seconds, which is in our case an unacceptable overhead.

If we load the program once and run it multiple times from the same, still running executable, the timings start at several ms. But for end-users this is not an option, they will run it from the commandline.

I would like to speed up the loading on first instantiating the executable. There is a small speedup between a cold start (after reboot of Windows) and a warm start, but only marginally so. What techniques or tools are available in .NET that we can use to speedup loading (note: we tried ILMERGE, which helps about 30% only and NGEN is not an option, it needs to be run at a variety of systems and architectures).

I was considering creating a service and/or a specific CLR hosting environment, but hopefully there is a simpler, more trivial solution. I have not tried GAC'ing yet.

like image 841
Abel Avatar asked Nov 11 '22 04:11

Abel


1 Answers

Use NGEN and multicore JIT. Refactor your application so that it needs less assemblies and less code at startup. Use ILMerge to reduce the number of assemblies and hopefully even trim away some unused code.

All of these are optimizations you can make. They do not offer groundbreaking improvements. .NET has no such options available.

Look into how DevArt Code Compare does it: They keep the compare app always running because it indeed takes seconds to launch it.

Have the app always running in the background. When launched from the command line just relay the command to the already running background process and forward the results. That makes the command line app tiny and launch quickly. It certainly does not need to load 50 assemblies.

This is probably the best you can do because it almost eliminates startup entirely.

like image 91
usr Avatar answered Nov 29 '22 16:11

usr