Native Compiler in
Native Compiler in
Hotel Antunovi
C# produktivnost + C++
performanse = .NET Native
Bahrudin Hrnjica, MVP C#
daenet
Agenda
1. Compiling .NET applications
2. RyuJIT next generation of JIT Compiler
3. .NET Native new way of compilation
4. 7 stage of .NET Native compilation
chain
5. .NET Native warm up Demo
6. Runtime directive in .NET Native
7. .NET Native Demo (Using RD, WCF .NET
Native)
8. Migration to .NET Native
9. Summary
JIT Compiler
JIT converts MSIL to native code at RunTime at the user machine.
Developers build MSIL assemblies
MSIL assemblies run on different
machines/architecture
MSIL assemblies contains managed code
JIT compilation converts IL code in to
native and stores in to memory
When the operation is called for the first
time JIT converts this part of the code in
to native.
Some of the code can never be used
NGen.exe
It performs the conversion from MSIL to
native code before rather than while
running the application
It compiles entire assembly at a time,
rather than a method at a time
It persist the generated code in the
Native Image Cache as file on the disk
de
mo
RyuJIT demo
How to enable using RyuJIT
.NET Native
Precompilation technology building
Windows Store app
.NET apps compiled to IL code.
At Run-Time JIT compiler translates IL
code in to native
At Design Time .NET Native directly
compiles C# apps targets .NET in to
native code
1. Enable
2. Debug/test
app
de
mo
Structure of rd directives
1. http://schemas.microsoft.com/netfx/201
3/01/metadata namespace
2. root element is the Directives element,
can contain:
0 or more Library elements
0 or more Application element
3. Application define
1. runtime reflection policy,
2. container for child elements
4. Library element
1. is simply a container
Rd.xml
degree declares what you're planning on doing
with that type or member at runtime,
Dynamic degree means that you're planning
to create objects or invoke methods dynamically
EG. DataContractSerializer degree means that you'll
serialize a class using the DataContractSerializer
Rd.xml - Examples
<Type Name="MyNamespace.MyClass"
Dynamic="Public" /> - MyClass is
available to dynamic reflection
<Namespace Name="MyNamespace"
Serialize="Required All" /> - include
all types from namespace and make them
Required whether is really need or not.
Rd.xml - recomendations
Replace the C# dynamic keyword with strongly
typed code
Skip compiled LINQ expressions because they are
interpreted instead of compiled and use reflection
too.
Instead of Type.GetType(MyWellKnownType),
consider typeof(MyWellKnownType).
Similarly, when you can, construct delegates directly
from methods instead of using
MethodInfo.CreateDelegate.
By using CallerMemberName attribute, it cause the
compiler to automatically fill in the string without
adding any reflection requirements.
de
mo
de
mo
Summary
Precompilation technology
Superior performance like C++
Productivity Development like C#
Optimized app memory usage
Only Windows Store App for now.
pitanja
Hvala!