views:

143

answers:

3

Working on .NET gives me good performance in general for the application itself but the initial load times for my application are quite large. A lot of it goes towards loading assemblies which is difficult to gauge.

Are there any optimizations that I can apply to my assemblies to make them faster to load without involving the GAC or Ngen and those are not available for ClickOnce?

This is a WinForms 2.0 project. I can upgrade it to a 3.5 but that limit my user base. I have .NET Framework 3.5 installed on my machine.

+1  A: 

You can use ILMerge to merge all your assemblies into one file. Reading one file into memory is faster then reading 10 files. Although I doubt you will see real improvement in load speed there.

You can also remove all the references to other assemblies, load the ui to the user, and while he uses the UI (typing or something else) preload all the needed assemblies using Assembly.Load, get all the needed function pointers using reflection and store them in internal members. This way application will load much faster. But I don't think any sane person will do optimization like this.

Alex Reitbort
+1  A: 

I have created a very small .exe that shows a splash screen asap. After that I initialize everything.

The JIT-compiler loads modules that are called from the method that is being jitted. So you have to take care that the method that shows the splash screen, does not call methods in modules that you do not want loaded yet.

Example:

internal sealed class Startup {

    // Call Startup.Run() from Program.Main to start the application
    internal void Run() {
        this.ShowSplash();
        this.ContinueStartup();
    }

    private void ShowSplash() {
        _splash = new Splash();
        _splash.Show();
        Application.DoEvents();
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private void ContinueStartup() {
        // Do the startup here
    }
}

The [MethodImpl(MethodImplOptions.NoInlining)] is needed so the ContinueStartup() method does not get inlined by the jit, because that will cause the modules to be loaded too early.

GvS
GvS, do u have any links to some examples about how to do this?
Pure.Krome
This looks pretty sweet. But a fancy splash screen isn't what I'm looking for. The users want to actually start using the program immediately and the perception of a splash screen isn't going to help much.
Jeremy Edwards
I know, but this is the best thing that worked for me. Show feedback to the user that everything is being loaded, is better as letting the user wait without feedback. If the user has to wait too long he/she will start the application again, and then startup times increases even more.
GvS
A: 

Can you describe your how many assemblies you have ?

.NET loads the assembly on the fly when you need them. You can decide to split your app in several assemblies. Assemblies must be divided by means of: deployment strategy, security and performance. Most apps are divided by 3 layered structure (UI, business, data).

Patrick Peters