NGen and Gacutil best practices
Asked Answered
B

3

7

I've been working on a WinForms application which has about 5 referenced assemblies - written by us, and about 8 referenced assemblies by third parties (we wont be hoping to update them in the future unless something goes terribly wrong - Infragistics/DevExpress components!).

Our startup times are a little too high on cold boots, what I'm wondering is whether adding them to the Gac and ngen'ing them is the way to go.

When we're installing into the NGen cache, does it need to be in the gac too? Whats the connection between the two? Which should I be aiming for? We have one exe, I'd do an ILMerge but I'm not sure that will work in our scenario - long story.

Also, is it possible to get how much memory my exe is taking - much like the Java applications do (like Netbeans!)

Beneficent answered 25/6, 2009 at 4:32 Comment(1)
You might want to have a dig round with a profiler to see what is causing the slowness first. ANTS (by RedGate) is a good one.Teufert
R
5

Main idea to improve startup time is to use delayed initialization whenever possible. Do not instantiate things that unnecessary immediately after startup. Use lazy init pattern. It is also possible to start background initialization worker after show main form to do non-critical initialization. Etc, etc, etc.

You can also check the following article (Improving Application Startup Time).

Regularize answered 25/6, 2009 at 8:20 Comment(1)
+1 for the CLR Inside Out article on Improving Application Startup Time. Very helpful. (You should include the title of the article in your hyperlink though -- I almost didn't click it.)Emmerich
C
0

Sounds to me that your problem definition is somehow implying your solution ☺

In other words, how do you know that the start up time is coming from loading the assemblies?

What you should do is to profile the app and make sure that's the case. It's possible, but what if some initialization is going on and you are focusing too much optimizing the wrong spot?

Here there are some tools that should help you out on profiling unmanaged apps.

Since you are talking about Winforms apps, I assume you have Visual Studio. If so, you can use its profiler for your managed app.

Good luck!

Clay answered 25/6, 2009 at 5:3 Comment(0)
E
0

If you are not using 3.5 SP1 of the .net framework you should consider benchmarking on that platform to see if you get a difference. There have been improvements made that might improve app startup times : CLR Optimizations In .NET Framework 3.5 SP1

This article also has some good general guidelines, ngen best practices, and tricks with avoiding the rebasing of your assemblies (although for the 5 or so referenced assemblies you are working with, dont expect miracles).

However its likely you'll get the most signficant reduction in startup time by seeking out the specific bottlenecks in your own particular app, as opposed to finding a quick fix elsewhere.

Existential answered 25/6, 2009 at 6:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.