Presentation is loading. Please wait.

Presentation is loading. Please wait.

.NET Native deep dive Andrew Pardoe

Similar presentations


Presentation on theme: ".NET Native deep dive Andrew Pardoe"— Presentation transcript:

1 .NET Native deep dive Andrew Pardoe (andrew.pardoe@microsoft.com)
Build 2014 4/17/2017 .NET Native deep dive Andrew Pardoe .NET Native Program Manager, .NET Runtime © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

2 Questions?

3 .NET code generation: A primer
Build 2014 4/17/2017 .NET code generation: A primer Source code (C#/VB/F#) MSIL bytecode Machine code C#/VB/F# compiler Code generation Code generation is done either…. Lazily at runtime with a Just-In-Time, or JIT, compiler Optimistically at build time with NGen, Triton or .NET Native © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

4 .NET Code Execution today
C++ Performance Self-contained apps Dynamic experience “Unlimited” class libraries

5 Code execution in CLR 4.5 Code generation
One JIT compiler for each architecture 64-bit JIT emphasizes code quality over throughput for server scenarios 32-bit JITs emphasize throughput over code quality for app scenarios Two native code generators with different deployment properties NGen runs on the user’s machine, at install time or automatically Triton runs in the Windows Phone 8 Store, app bound to libraries at install One runtime (VM or VEE) spans multiple scenarios Desktop CLR for Windows Client and Server workloads (different GC modes) CoreCLR for Mobile and targeted Server workloads built from the same codebase

6 Triton: Native code on Windows Phone
Build 2013 4/17/2017 Triton: Native code on Windows Phone MDIL native code C# MSIL MSIL  MDIL Windows Phone apps are compiled to native code in the cloud on WP8 © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

7 The properties of code execution
Code generation properties Throughput Code quality Memory usage Deployment properties Distribution format Acquisition process Serviceability Security properties Typesafe execution Code identity & isolation Security functionality Developer experience Everything is a tradeoff! “Make simple things easy and hard things possible.”

8 .NET Code Execution tomorrow
.NET Native RyuJIT & CLR VM C# Productivity with C++ Performance C# Language with dynamic experiences Today: One runtime engine & same code execution for all scenarios Tomorrow: Refactored engine & multiple execution strategies provide best of class on both extremes. From there, we target the middle.

9 .NET Native (Project N)

10 .NET Native

11 Wordament on .NET Native:
Build 2014 4/17/2017 .NET Native Next Generation Compiler in the Cloud for Store Apps represents an evolution of Triton & NGen Uses lean runtime and VC++ optimizer for fast code execution and reduced memory usage Based on a refactored CLR engine. Native code is shared, managed code has moved into the libraries Provides converged developer experience for .NET across devices . Wordament on .NET Native: Scenario Improvement (%) Cold Startup 39.32% Warm Startup 31.21% Memory Usage 12.68% © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

12 Visual Studio Experience for .NET Native
Debug and test your app with .NET Native Enable .NET Native for your project

13 .NET Native Compiler Toolchain

14 IL Compiler: C# -> MSIL
Compile C# source code Generate & compile marshalling and serialization code

15 Pregenerated interop code
Today, interop code is generated as MSIL at runtime, JIT-compiled, executed and thrown out JIT compilation takes time (but the methods are small) If your P/Invoke signature has an issue your compiled code is gone In .NET Native, the Marshalling Code Generator creates interop code as a C# file at compile-time Compilation is done at build-time The code can be debugged as C#, not assembly The code can be inspected and optimized before compilation to MSIL

16 IL Compiler: Merge & reduce app code
Merge all app & library code “Reduce” app to throw away unneeded types, code, metadata, etc.

17 Static dynamic code (dynamic static code?)
A bit of a conundrum… Static compilation means any code that can run is generated at compile-time Reflection requires that anything you can inspect at runtime can be executed The solution: preserve the set of classes, methods, generic types, etc., that the code might want to call And if the compiler gets it wrong? Missing metadata results in an exception File a bug with the .NET Native team?

18 Runtime directives (default.rd.xml)
<Directives xmlns=" <Application> <Assembly Name="*Application*" Dynamic="Required All" /> <!-- Add your application specific runtime directives here. --> </Application> </Directives> The type specifies the class, namespace or assembly affected Types: class, interface, or struct Group of types: namespace, assembly (*Application* is all types in the app assemblies) Type member: method, field, property, or event The degree tells the compiler what behavior is needed Reflection behaviors, Serialization behaviors, Interop behaviors The policy notes the scope to apply that behavior inside the type Accessibility: All, Public, Private, Internal Required: Including this keyword means “Include these types in the final binary”

19 IL Compiler: MSIL -> MDIL -> machine code
C++ optimizer compiles MSIL to MDIL, Machine Dependent Intermediate Format. App is mostly machine code but cannot execute. “Bind” MDIL app code into machine code. App distributed as a stub, app.exe, and app code in a dll. MRT Runtime is distributed in the app package, making the app package self-sufficient.

20 Example: automatic vectorization/parallelization
for (long j = 0; j < numBodies; j++) // From Nbody sample { Float_4 r; r.x = A[j].pos.x - B.pos.x; r.y = A[j].pos.y - B.pos.y; r.z = A[j].pos.z - B.pos.z; float distSqr = r.x * r.x + r.y * r.y + r.z * r.z; distSqr += softeningSquared; float invDist = 1.0f / (float)Math1.Sqrt(distSqr); float invDistCube = invDist * invDist * invDist; float s = fParticleMass * invDistCube; acc.x += r.x * s; acc.y += r.y * s; acc.z += r.z * s; } The C++ optimizer can recognize this code as parallel and generate vector (SIMD) instructions

21 .NET Native performance gains
Build 2014 4/17/2017 .NET Native performance gains Optimized runtime Refactored core libraries Pregenerated interop Pregenerated serializers Tree-shaken code Pay-for-play metadata C++ optimizer Global optimizations © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

22 .NET Native: Call to action
Build 2014 4/17/2017 .NET Native: Call to action Learn more about .NET Native Download the .NET Native VS add-In Requires Visual Studio 2013 Update 2 RC Try out your Store app with .NET Native Do you have a top Store app or library? Reach out to us: Help us make .NET Native better Participate in the .NET Native Forum Reach out to us: © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

23 We would love to hear from you!
Build 2014 4/17/2017 We would love to hear from you! Blog dotnet @dotnet MSDN Forums UserVoice © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.


Download ppt ".NET Native deep dive Andrew Pardoe"

Similar presentations


Ads by Google