Could explain how the .net assemblies (Dlls) work when they are used
by an exe -- I'd much appreciate it. If your exe is making a call to a
function that's part of the .net framework library (ie
System.Math.Ceiling), the amount of time taken up on the first call to
the specific function is usually about 80-90% more than when the
function is called again. Can someone explain to me why this works as
it does? I know that when you use a Dll, it's got to get loaded into
the system and map all of proc addresses for the functions into
memory. On the first call, are these mapping of the function to a
particular location in memory left blank and is the majority of time
spent filling in these mappings?

This brings up the question of whether there is a way to load the Dlls
you're going to use for a certain EXE and set it up so everything is
pre-cached? Is it possibly a setting for your project in Visual
Studio.net?

Apologies if this sounds vague but I'm not entirely familiar with this
stuff just yet.

Thanks,
Justin

Re: Why does a call to a function in a dll take less time if you call it repeatedly? by Ed

Ed
Sat Feb 21 20:18:23 CST 2004

Beyond the memory loading and mapping, IL libaraies also have to be JIT
compiled (from IL to x86, for example) when loaded for the first time. After
that, the cached native code is reused, which is much faster.

"Justin Galzic" <jgalzic@hotmail.com> wrote in message
news:2fd711c3.0402211744.21a2edf5@posting.google.com...
> Could explain how the .net assemblies (Dlls) work when they are used
> by an exe -- I'd much appreciate it. If your exe is making a call to a
> function that's part of the .net framework library (ie
> System.Math.Ceiling), the amount of time taken up on the first call to
> the specific function is usually about 80-90% more than when the
> function is called again. Can someone explain to me why this works as
> it does? I know that when you use a Dll, it's got to get loaded into
> the system and map all of proc addresses for the functions into
> memory. On the first call, are these mapping of the function to a
> particular location in memory left blank and is the majority of time
> spent filling in these mappings?
>
> This brings up the question of whether there is a way to load the Dlls
> you're going to use for a certain EXE and set it up so everything is
> pre-cached? Is it possibly a setting for your project in Visual
> Studio.net?
>
> Apologies if this sounds vague but I'm not entirely familiar with this
> stuff just yet.
>
> Thanks,
> Justin



Re: Why does a call to a function in a dll take less time if you call it repeatedly? by jgalzic

jgalzic
Sun Feb 22 17:36:26 CST 2004

Ed, thanks for answering to my post. If the underlying CIL is complied
with JIT compiler only when the assembly is loaded, is it possible to
do the JIT compilation of all of the functions that you'll use from a
particular set of libraries ahead of time before the actual time
you'll go to use them so everything is cached as native code right
away?

Justin

"Ed Kaim [MSFT]" <edkaim@online.microsoft.com> wrote in message news:<eODBroO#DHA.3848@TK2MSFTNGP10.phx.gbl>...
> Beyond the memory loading and mapping, IL libaraies also have to be JIT
> compiled (from IL to x86, for example) when loaded for the first time. After
> that, the cached native code is reused, which is much faster.
>
> "Justin Galzic" <jgalzic@hotmail.com> wrote in message
> news:2fd711c3.0402211744.21a2edf5@posting.google.com...
> > Could explain how the .net assemblies (Dlls) work when they are used
> > by an exe -- I'd much appreciate it. If your exe is making a call to a
> > function that's part of the .net framework library (ie
> > System.Math.Ceiling), the amount of time taken up on the first call to
> > the specific function is usually about 80-90% more than when the
> > function is called again. Can someone explain to me why this works as
> > it does? I know that when you use a Dll, it's got to get loaded into
> > the system and map all of proc addresses for the functions into
> > memory. On the first call, are these mapping of the function to a
> > particular location in memory left blank and is the majority of time
> > spent filling in these mappings?
> >
> > This brings up the question of whether there is a way to load the Dlls
> > you're going to use for a certain EXE and set it up so everything is
> > pre-cached? Is it possibly a setting for your project in Visual
> > Studio.net?
> >
> > Apologies if this sounds vague but I'm not entirely familiar with this
> > stuff just yet.
> >
> > Thanks,
> > Justin

Re: Why does a call to a function in a dll take less time if you call it repeatedly? by Ed

Ed
Sun Feb 22 17:57:13 CST 2004

Check out Ngen at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfnativeimagegeneratorngenexe.asp.

"Justin Galzic" <jgalzic@hotmail.com> wrote in message
news:2fd711c3.0402221536.9e58841@posting.google.com...
> Ed, thanks for answering to my post. If the underlying CIL is complied
> with JIT compiler only when the assembly is loaded, is it possible to
> do the JIT compilation of all of the functions that you'll use from a
> particular set of libraries ahead of time before the actual time
> you'll go to use them so everything is cached as native code right
> away?
>
> Justin
>
> "Ed Kaim [MSFT]" <edkaim@online.microsoft.com> wrote in message
news:<eODBroO#DHA.3848@TK2MSFTNGP10.phx.gbl>...
> > Beyond the memory loading and mapping, IL libaraies also have to be JIT
> > compiled (from IL to x86, for example) when loaded for the first time.
After
> > that, the cached native code is reused, which is much faster.
> >
> > "Justin Galzic" <jgalzic@hotmail.com> wrote in message
> > news:2fd711c3.0402211744.21a2edf5@posting.google.com...
> > > Could explain how the .net assemblies (Dlls) work when they are used
> > > by an exe -- I'd much appreciate it. If your exe is making a call to a
> > > function that's part of the .net framework library (ie
> > > System.Math.Ceiling), the amount of time taken up on the first call to
> > > the specific function is usually about 80-90% more than when the
> > > function is called again. Can someone explain to me why this works as
> > > it does? I know that when you use a Dll, it's got to get loaded into
> > > the system and map all of proc addresses for the functions into
> > > memory. On the first call, are these mapping of the function to a
> > > particular location in memory left blank and is the majority of time
> > > spent filling in these mappings?
> > >
> > > This brings up the question of whether there is a way to load the Dlls
> > > you're going to use for a certain EXE and set it up so everything is
> > > pre-cached? Is it possibly a setting for your project in Visual
> > > Studio.net?
> > >
> > > Apologies if this sounds vague but I'm not entirely familiar with this
> > > stuff just yet.
> > >
> > > Thanks,
> > > Justin



Re: Why does a call to a function in a dll take less time if you call it repeatedly? by Chris

Chris
Mon Feb 23 12:06:24 CST 2004

Besides ngen, you could write a method that references all the methods you
want compiled, and call that method, like this:

void TriggerJIT() {
if (1 == 0) {
myObj.MethodToCompileA();
myObj.MethodToCompileB();
myObj.MethodToCompileC();
Math.Ceiling(0);
}
}

The only caveat is that you couldn't apply any compiler optimizations that
do dead-code elimination. You could put this method in a seperate assembly
and never compile it with optimizations, or if you don't need to, you could
just leave optimizations out of your main assembly.

Chris Capel

"Justin Galzic" <jgalzic@hotmail.com> wrote in message
news:2fd711c3.0402221536.9e58841@posting.google.com...
> Ed, thanks for answering to my post. If the underlying CIL is complied
> with JIT compiler only when the assembly is loaded, is it possible to
> do the JIT compilation of all of the functions that you'll use from a
> particular set of libraries ahead of time before the actual time
> you'll go to use them so everything is cached as native code right
> away?
>
> Justin
>
> "Ed Kaim [MSFT]" <edkaim@online.microsoft.com> wrote in message
news:<eODBroO#DHA.3848@TK2MSFTNGP10.phx.gbl>...
> > Beyond the memory loading and mapping, IL libaraies also have to be JIT
> > compiled (from IL to x86, for example) when loaded for the first time.
After
> > that, the cached native code is reused, which is much faster.
> >
> > "Justin Galzic" <jgalzic@hotmail.com> wrote in message
> > news:2fd711c3.0402211744.21a2edf5@posting.google.com...
> > > Could explain how the .net assemblies (Dlls) work when they are used
> > > by an exe -- I'd much appreciate it. If your exe is making a call to a
> > > function that's part of the .net framework library (ie
> > > System.Math.Ceiling), the amount of time taken up on the first call to
> > > the specific function is usually about 80-90% more than when the
> > > function is called again. Can someone explain to me why this works as
> > > it does? I know that when you use a Dll, it's got to get loaded into
> > > the system and map all of proc addresses for the functions into
> > > memory. On the first call, are these mapping of the function to a
> > > particular location in memory left blank and is the majority of time
> > > spent filling in these mappings?
> > >
> > > This brings up the question of whether there is a way to load the Dlls
> > > you're going to use for a certain EXE and set it up so everything is
> > > pre-cached? Is it possibly a setting for your project in Visual
> > > Studio.net?
> > >
> > > Apologies if this sounds vague but I'm not entirely familiar with this
> > > stuff just yet.
> > >
> > > Thanks,
> > > Justin



Re: Why does a call to a function in a dll take less time if you call it repeatedly? by Chris

Chris
Mon Feb 23 12:09:34 CST 2004

Nevermind that. I was confused.

"Chris Capel" <aoeu@nothing.com> wrote in message
news:e2Hyqej%23DHA.1052@TK2MSFTNGP12.phx.gbl...
> Besides ngen, you could write a method that references all the methods you
> want compiled, and call that method, like this:
>
> void TriggerJIT() {
> if (1 == 0) {
> myObj.MethodToCompileA();
> myObj.MethodToCompileB();
> myObj.MethodToCompileC();
> Math.Ceiling(0);
> }
> }
>
> The only caveat is that you couldn't apply any compiler optimizations that
> do dead-code elimination. You could put this method in a seperate assembly
> and never compile it with optimizations, or if you don't need to, you
could
> just leave optimizations out of your main assembly.
>
> Chris Capel
>
> "Justin Galzic" <jgalzic@hotmail.com> wrote in message
> news:2fd711c3.0402221536.9e58841@posting.google.com...
> > Ed, thanks for answering to my post. If the underlying CIL is complied
> > with JIT compiler only when the assembly is loaded, is it possible to
> > do the JIT compilation of all of the functions that you'll use from a
> > particular set of libraries ahead of time before the actual time
> > you'll go to use them so everything is cached as native code right
> > away?
> >
> > Justin
> >
> > "Ed Kaim [MSFT]" <edkaim@online.microsoft.com> wrote in message
> news:<eODBroO#DHA.3848@TK2MSFTNGP10.phx.gbl>...
> > > Beyond the memory loading and mapping, IL libaraies also have to be
JIT
> > > compiled (from IL to x86, for example) when loaded for the first time.
> After
> > > that, the cached native code is reused, which is much faster.
> > >
> > > "Justin Galzic" <jgalzic@hotmail.com> wrote in message
> > > news:2fd711c3.0402211744.21a2edf5@posting.google.com...
> > > > Could explain how the .net assemblies (Dlls) work when they are used
> > > > by an exe -- I'd much appreciate it. If your exe is making a call to
a
> > > > function that's part of the .net framework library (ie
> > > > System.Math.Ceiling), the amount of time taken up on the first call
to
> > > > the specific function is usually about 80-90% more than when the
> > > > function is called again. Can someone explain to me why this works
as
> > > > it does? I know that when you use a Dll, it's got to get loaded into
> > > > the system and map all of proc addresses for the functions into
> > > > memory. On the first call, are these mapping of the function to a
> > > > particular location in memory left blank and is the majority of time
> > > > spent filling in these mappings?
> > > >
> > > > This brings up the question of whether there is a way to load the
Dlls
> > > > you're going to use for a certain EXE and set it up so everything is
> > > > pre-cached? Is it possibly a setting for your project in Visual
> > > > Studio.net?
> > > >
> > > > Apologies if this sounds vague but I'm not entirely familiar with
this
> > > > stuff just yet.
> > > >
> > > > Thanks,
> > > > Justin
>
>