MD2014_.NET Native v2.pptx

Preview:

Citation preview

Bahrudin Hrnjica, Bihaćbahrudin.hrnjica@daenet.eu

http://developers.de http://bhrnjica.net

C# produktivnost + C++ performanse = .NET Native

AgendaWhat new in .NET 4.6 and VS 2015Compiling .NET applicationsRyuJIT next generation of JIT Compiler.NET Native new way of compilation.NET Native DemoRuntime directive in .NET NativeMigration to .NET NativeSummary

.NET Innovation

Cross-Platform

Open Source

The road ahead for .NET.NET Core

ASP.NET 5

.NET 2015

RyuJIT + SIMDGarbage Collector

Runtime components

Compilers.NET Compiler Platform (Roslyn)Languages innovation

.NET Framework 4.6 .NET Core 5

Fully-featured and integrated .NET libraries and runtime for Windows

Modular and optimized .NET libraries and runtimes

WPF ASP.NET (4 & 5)

Windows Forms

ASP.NET 5 Universal Windows Apps

CoreCLR .NET Native

Base class librariesNuGet packages

LibrariesShared

.NET Framework 4.6

.NET Framework

4

.NET Framework

4.5

.NET Framework

4.5.1

.NET Framework

4.5.2

.NET Framework 4.6

Evolution in time

• Highly compatible, in-place replacement for .NET 4, 4.5, 4.5.1, and 4.5.2

• Full support of any .NET API and Libraries in the market

• WPF is the platform of choice for desktop application development

• ASP.NET 5 is also supported running on top of .NET 4.6

• .NET 4.6 also gets the investment on new compilers, new Jit, and languages innovation

Performance and reliability improvement on touch stack• Touch events in multi-touch are reported more reliably• Better performance of touch when UI thread is busy

Scrolling and virtualization improvements• Reliable traversal in a list• Preventing layout cycles during virtualization

HDPI Improvements• Multi-dpi cursor and monitor support• Smarter rounding of framework elements

Connect bugs >10 votes reactivated for investigation • 4/5 fixed of .NET 4.6 RTM

WPF Improvements in .NET 4.6

The new Blend for Visual Studio 2015Integrated with VS technologies like Solution Explorer, Team Explorer, Editor

New Language Service based on “Roslyn”Faster and more reliableCode centric workspace in VS, In-place editing support for WPF

DebuggingUI Debugging Tools for Xaml, Debugger-Integrated Diagnostic Tools

DiagnosticsTimeline tool

WPF Tooling in VS 2015

.NET Compiler Platform (“Roslyn”) FROMIsolated/closed compilersHard to extend dev experience

C#, VBSource code

.exe/.dilIL assemblies

Established .NET compilers

TOAPI: open platformRich IDE experiences/refactoringCode analysisCustom diagnosticsOpen Source compilers .NET Compilers Platform

(a.k.a. ROSLYN)

C#, VBSource code

.exe/.dilIL assemblies

Open platform for developers

Language and IDE

VS dev experience extensibility

Open Source

.NET Compiler Platform (“Roslyn”)

Scenarios/usage cases

OSS

API

C#VBNew public preview today! (April

2014)http://aka.ms/NETCompilerPlatform

“Roslyn” is the basis for .NET and Visual Studio vNext“Roslyn” is OPEN SOURCEhttp://aka.ms/RoslynOSS

Universal Windows Platform

• Next Generation Compiler in the Cloud for Store Apps

• Uses lean runtime and VC++ optimizer for fast code execution and reduced memory usage

• Preview available from Visual Studio http://aka.ms/dotnetnative

Universal Windows PlatformShared across Windows and Windows Phone apps

.NET NativeNative code compilation

Universal Windows Platform

.NET Native highlights

ASP.NET 5.0Cloud-ready• Leaner, faster, simpler• Designed from top to bottom to

be ready for the cloud and cross-platform deployments

Modular and open• More flexible with open source

and modular implementation

Improved tooling and frameworks• Deliver value faster with

improved tooling and frameworks

.NET Cross-Platform

Mono

.NET Core cross-platform Mobile Development and .NET/Xamarin partnership

.NETXamarin

Unity

Services and Web applications

Mobile apps

Windows Linux Mac OS X .NET Core

ASP.NET 5

• Available Now!• .NET Core 5 on Windows• .NET Core 5 on Linux• .NET Core 5 on MacOS

.NET Core Preview

OpennessCommunityRapid innovation

The .NET Foundation .NET API for Hadoop WebClient

.NET Compiler Platform ("Roslyn").NET Map Reduce API for Hadoop

.NET Micro Framework

ASP.NET MVCASP.NET Web API

ASP.NET Web Pages

ASP.NET SignalR

MVVM Light Toolkit

.NET Core 5

Orleans

MEF (Managed Extensibility Framework)

OWIN Authentication MiddlewareRx (Reactive Extensions)

Orchard CMS Windows Azure .NET SDK

Thinktecture IdentityManagerWnsRecipe

Mimekit Xamarin.AuthXamarin.Mobile

Couchbase for .NET

Meet the people behind the .NET Foundationhttp://www.dotnetfoundation.org/team

Join the conversationhttp://www.dotnetfoundation.org @dotnetfdn

MailkitSystem.Drawing

ASP.NET 5

Salesforce Toolkits for .NET

NuGetKudu Cecil

MSBuild

Compilation of .NET applicationsTwo ways of compilation MSIL to native code

1. .NET Framework just-in-time (JIT) compiler2. .NET Framework Native Image Generator (Ngen.exe)

JIT Compiler• JIT converts MSIL to native code at Run-Time 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

RyuJIT new .NET JIT Compiler

• 64 bit JIT – twice slower than 32JIT• RyuJIT the same code base

as 32JIT• RyuJIT for 64 bit architecture• RyuJIT app 30% faster than

32JIT

Install and setting RYUJIT• two ways to turn on RyuJIT. • set an environment variable: COMPLUS_AltJit=*• for entire machine, set the registry key HKLM\SOFTWARE\

Microsoft\.NETFramework\AltJit to the string "*".• Both methods cause the 64-bit CLR to use RyuJIT instead of

JIT64. • And both are temporary settings—installing RyuJIT doesn’t

make any permanent changes to your machine (aside from installing the RyuJIT files in a directory)

How to DISABLE RYUJITthree ways to turn off RyuJIT.

• Add config section:• <runtime>• <useLegacyJit enabled="0" />• </runtime>

• set an environment variable: COMPLUS_useLegacyJit=1• for entire machine, set the registry key HKLM\SOFTWARE\Microsoft\.NETFramework\

useLegacyJit to the string "*".

Both methods cause the 64-bit CLR to use JIT64 instead of RyuJIT.

.NET NativeNext Generation Compiler in the Cloud for Store Apps

Provides converged developer experience for .NET across devices

Uses lean runtime and VC++ optimizer for fast code execution and reduced memory usage

Answer: Mobile app requirements

• Faster app startup times• No JIT would also imply less CPU cycles, hence longer battery life• Up to 60% savings on cold startup• Up to 40% savings on warm startup

• Smaller memory footprint• Whole program optimization removes unused types/functions• Up to 30% savings for apps

Why .NET Native?

Answer: Adaptive apps

• Writing code against APIs that don’t exist on a device becomes common

• JIT will cause the code above to crash on most Windows 10 devices

Why .NET Native?

Answer: Faster cadenceWhy .NET Native?

• Coupling between Windows and .NET historically

• Ship .NET updates and tooling improvement faster

• Updates should not break developers• NET Native statically links (most) framework libraries with the app• Apps adopt library innovations on their cadence• Developers can be confident that Windows Update won’t break their app

• .NET Native was already being used by some Windows 8.1 apps as a pilot!

Did you know?

All Universal Windows 10 .NET apps delivered to consumer devices will be compiled with .NET Native

Developer workflowCreate a C#/VB Universal Windows Project

Develop and Debug

Debug x86|x64|ARM

Create package for store submission

Test Scenarios

Release x86|x64|ARM

Store compiles AppX w/ .NET Native Toolchain

Consumer Devices install .NET Native enabled AppX packages

Anatomy of a Universal Windows app projectDemo

Developer workflowCreate a C#/VB Universal Windows Project

Build & Run

Debug x86|x64|ARM

Created package for Store submission

Test Scenarios

Release x86|x64|ARM

Store compiles AppX w/ .NET Native Toolchain

Consumer Devices install .NET Native enabled AppX packages

Uses AppLocal CoreCLR runtime WinMetadata\Windows.winmd for avoiding JIT failures.NET references are copied local to the package

Uses .NET Native toolchainUpload Release .appxupload files to the Store Side-load Release AppX packagesPackage revision is reserved for store-side compilation

• Deployment targets• x86 for local machine, Simulator and Emulator scenarios• ARM for phone devices

• Library authors can still ship binaries as AnyCPU

But I love my AnyCPU…

• Debug• AppX packages defaulted to MSIL• No .appxupload files created

• Release• AppX packages defaulted to .NET Native• Used for enterprise/side-loading scenarios

• Packages in .appxupload are MSIL• Store will reject .NET Native package submissions

Default Packaging options at VS 2015 RTM

Default policy is conservative for apps

Used to declare what Metadata and Types to keep• Flexible to allow assembly, namespace or type-level

specifications• Developers can change policy to decrease app footprint

Control library authors• Use rd.xml as an embedded resource to specify

types/properties that are used via Reflection

Runtime Directives (rd.xml)

Runtime DirectivesDemo

• Develop your application using Debug

• Periodically test your application using Release• Issues specific to .NET Native can be better diagnosed with .NET Native

enabled in Debug builds

• Submitting AppX to store• Common scenario is AppXUpload• Create custom Release build packages with

<EnableDotNetNative>False</EanableDotNetNative>

.NET Native best practices

• Developer experience improvements around build throughput and incremental build

• Introduction of a shared framework package that reduces per-app size-on-disk

.NET Native running backlog

• Maintain forks of your sources

• .NET Native compilation happens in the cloud

• Symbols available on the Developer portal

Post mortem debugging

• Edit-n-Continue• IntelliTrace• Just my Code• Obfuscation

VS .NET Native unsupported experiences

• Universal Windows 10 apps will have the same base surface area as Windows 8.1• And yes, that means WCF works on Phone

• Future libraries will be delivered out-of-band via NuGet• First examples in default project templates:

System.Numerics.Vector.dll, etc.

.NET Framework evolution

• Portable Class Libraries• PCLs that target .NETCore 4.5.1 should work as-is

• Native references• Windows or Windows Phone 8.1 component• Reference the Visual Studio 2013 CRT packaged as Universal Windows

App package

• Universal Windows App competent• Reference the Visual Studio 2015 CRT package

• Your app can use both sets of references!

Consuming libraries in your .NET app

• Precompilation technology • Superior performance like C++• Productivity Development like C#• Optimized app memory usage• Only Windows Store App for now.

Summary

.NET Innovation

Cross-Platform

Open Source

The road ahead for .NET.NET Core

ASP.NET 5