41
Bahrudin Hrnjica, Bihać [email protected] http:// developers.de http://bhrnjica.net C# produktivnost + C++ performanse = .NET Native

MD2014_.NET Native v2.pptx

Embed Size (px)

Citation preview

Page 1: MD2014_.NET Native  v2.pptx

Bahrudin Hrnjica, Bihać[email protected]

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

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

Page 2: MD2014_.NET Native  v2.pptx

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

Page 3: MD2014_.NET Native  v2.pptx

.NET Innovation

Cross-Platform

Open Source

The road ahead for .NET.NET Core

ASP.NET 5

Page 4: MD2014_.NET Native  v2.pptx

.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

Page 5: MD2014_.NET Native  v2.pptx

.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

Page 6: MD2014_.NET Native  v2.pptx

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

Page 7: MD2014_.NET Native  v2.pptx

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

Page 8: MD2014_.NET Native  v2.pptx

.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

Page 9: MD2014_.NET Native  v2.pptx

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

Page 10: MD2014_.NET Native  v2.pptx

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

Page 11: MD2014_.NET Native  v2.pptx

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

Page 12: MD2014_.NET Native  v2.pptx

.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

Page 13: MD2014_.NET Native  v2.pptx

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

.NET Core Preview

Page 14: MD2014_.NET Native  v2.pptx

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

Page 15: MD2014_.NET Native  v2.pptx

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)

Page 16: MD2014_.NET Native  v2.pptx

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

Page 17: MD2014_.NET Native  v2.pptx

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

Page 18: MD2014_.NET Native  v2.pptx

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

Page 19: MD2014_.NET Native  v2.pptx

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)

Page 20: MD2014_.NET Native  v2.pptx

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.

Page 21: MD2014_.NET Native  v2.pptx

.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

Page 22: MD2014_.NET Native  v2.pptx

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?

Page 23: MD2014_.NET Native  v2.pptx

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?

Page 24: MD2014_.NET Native  v2.pptx

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

Page 25: MD2014_.NET Native  v2.pptx

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

Did you know?

Page 26: MD2014_.NET Native  v2.pptx

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

Page 27: MD2014_.NET Native  v2.pptx

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

Page 28: MD2014_.NET Native  v2.pptx

Anatomy of a Universal Windows app projectDemo

Page 29: MD2014_.NET Native  v2.pptx

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

Page 30: MD2014_.NET Native  v2.pptx

• 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…

Page 31: MD2014_.NET Native  v2.pptx

• 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

Page 32: MD2014_.NET Native  v2.pptx

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)

Page 33: MD2014_.NET Native  v2.pptx

Runtime DirectivesDemo

Page 34: MD2014_.NET Native  v2.pptx

• 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

Page 35: MD2014_.NET Native  v2.pptx

• 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

Page 36: MD2014_.NET Native  v2.pptx

• Maintain forks of your sources

• .NET Native compilation happens in the cloud

• Symbols available on the Developer portal

Post mortem debugging

Page 37: MD2014_.NET Native  v2.pptx

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

VS .NET Native unsupported experiences

Page 38: MD2014_.NET Native  v2.pptx

• 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

Page 39: MD2014_.NET Native  v2.pptx

• 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

Page 40: MD2014_.NET Native  v2.pptx

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

Summary

Page 41: MD2014_.NET Native  v2.pptx

.NET Innovation

Cross-Platform

Open Source

The road ahead for .NET.NET Core

ASP.NET 5