URGENT: Please Help: .Net dll compilation time

  • Thread starter Thread starter MR
  • Start date Start date
M

MR

Hi,
it has been observed that when we try to instantiate
a .Net dll for the first time in a session (e.g. from an
exe in .Net), it takes almost 10 times compared to
subsequent instantiations.

We have A.exe, developed in VB.Net, where, in a button
click, we are instantiating the Test.dll also developed in
VB.Net. We run three instances of A.exe simultaneously
(say A1, A2 and A3 are the three instances). Clicking on
the button in A1, A2 and A3 for the first time, it takes
almost 2000 miliseconds to instantiate the dll in each
instance (A1, A2, A3). Clicking the second time onwards,
the time for instantiation reduces to 130 miliseconds.

My questions are:
1. As I understand a dll can take more time in the first
instantiation. But why is it taking more time in the first
click from each of the exe instances instead of just the
very first click from A1? Why is it session/connection
dependent?

2. Is there any way we can ensure that the dll
instantiates in the fastest possible time in the very
first try?

It would great if someone can please help.

Thanks,
M.R.
 
Hi MR,

.Net is a Just in time compiled platform so the first click on a button it
takes time to compile all the methods that are being called by that click
but each subsequent click is fast because .Net doesn't need to compile that
code again. The reason you are seeing this per-instance rather than system
wide is that the a .Net assembly (dll or exe) is loaded in to each process
independently. Each process creates what is called an AppDomain (a process
contains at least one default domain but can contain more) that contains
the assemblies loaded for that program.

As far as beating this performance hit, we have a utility that ships with
the .Net framework called ngen.exe. ngen performs the Just in Time compile
step in advance and saves the native code image created to a system cache
where it can be used for speedier execution. If you run the ngen utility on
your assemblies then run them, you should see an increase in performance.
In fact, this is one of Microsoft's recomended performance enhancements.

For more information about writing performant managed code, check out:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/highperfmanagedapps.asp?frame=true

For more information about ngen, check out:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/htm
l/cpgrfnativeimagegeneratorngenexe.asp

--
Michal Sampson VB .Net Deployment Developer
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
--------------------
 
Back
Top