JIT Compilation
16 November 2014
the C# source code was compiled into IL by C# compiler, and at runtime, the JIT compiler will compile the IL into Native code, the JIT compiler compiles the code on a method-by-method basis, if the method has been JITed, it will not be JITed again.
JIT compilation can hurt startup times. so here comes NGen
.
NGen can precompile IL to native code, that can be done before run time
Microsoft is now working on a replacement JIT called RyuJIT
Inlining
JIT compiler will replace method call with method body in the call site, for example
int add(int x, int y) {
return x + y;
}
int z = add(4,5);
will be optimized to
int z = 4 + 5
this will get rid of method call overhead
when JIT will inline a method
- Don’t contain exception handling (try…catch)
- Are not virtual
- Are not recursive
[MethodImpl(MethodImplOptions.NoInlining)] tells JIT never inline this method
void Method1()
[MethodImpl(MethodImplOptions.AggressiveInlining)] tells JIT always inline this method when possible
void Method2()
blog comments powered by Disqus