440 likes | 785 Views
TOOL-813T. Deep dive into the kernel of the .NET Framework. Mark Miller Pracheeti Nagarkar Senior SDET Program Manager II .NET Core Platform Team Microsoft Corporation. Quick Reminder – What Is The CLR. Entity Frame-work. ASP. NET. WCF. WPF. Win Forms. Work Flow. And more!.
E N D
TOOL-813T Deep dive into the kernel of the .NET Framework Mark Miller Pracheeti Nagarkar Senior SDET Program Manager II .NET Core Platform Team Microsoft Corporation
Quick Reminder – What Is The CLR Entity Frame-work ASP. NET WCF WPF Win Forms Work Flow And more! The CLR Base Class Libraries Profiling& Debugging APIs JIT & NGEN Garbage Collector Security Model Exception Handling Loader & Binder
Agenda slide WHO WILL BENEFIT FROM THIS TALK TOPICS WHAT YOU’LL LEAVE WITH • What’s new in the 4.5 CLR • How you can leverage it • Performance Improvements to CLR in .NET Framework 4.5 • GC • Managed Profile Guided Optimizations • Automatic NGen • Multi-core JIT • Diagnostics Improvements to CLR in .NET Framework 4.5 • Re-JIT • .NET Developers
Generation 1 Generation 0 Quick Reminder – GC Fundamentals Roots Heap • New objects allocated as Generation 0 • Accessible References Keep Objects Alive • GC Compacts Referenced Objects • Objects Promoted to Older Generation
Quick Reminder – GC Fundamentals • 2 Modes: Client (default) and Server • Heaps • Collection Flavors
Quick Reminder - Server Mode (4.0) • (.NET 4.0) Maximizes application scalability
Background GC For Server Mode (New in 4.5)Performance: Reduces pause times (Desktop apps) • (.NET 4.5) Gen0/Gen1 collections can proceed during Gen2 GC
Other GC ImprovementsPerformance • (Server GC) Scalable Marking for full blocking GCs • Large Object Heap Allocation Improvements • Better use of free space on LOH • (Server only) Balancing the LOH allocations across processors • … And More! LEARN MORE http://blogs.msdn.com/b/clrteam/ “Enhancements to the CLR GC in .NET 4.5”
Problems Memory usage Startup Time
Managed Profile Guided OptimizationPerformance: Improves startup time, memory usage (All apps) • Let’s reduce the number of pages loaded from disk. • Let’s reduce the number of copy-on-write pages. Hot Hot Copy on Write HOT Copy on Write
Managed Profile Guided OptimizationPerformance: Improves startup and execution time (All apps) Hot/Cold Hot/Cold Read-Only/Write DATA CLR Data Structures, Metadata CODE Basic Blocks
Managed Profile Guided OptimizationPerformance: Improves startup and execution time (All apps) BUILD SETUP RUN • Identify Scenario • Generate Profile Data • Embed data into IL • Generate Native Image • Page density improved • Lower memory use
Managed Profile Guided OptimizationUsage of MPGO.exe • MPGO –scenario “MyTax.exe /params foo” –AssemblyList“Mytax.dll MyTaxUtil2011.dll” –OutDir “C:\Optimized” –TimeOut 15 • MPGO –scenario “wav2wma.exe –input song1.wav –output song1.wma” –AssemblyList“transcode.dll” –OutDir “C:\Optimized” –TimeOut 15 LEARN MORE http://blogs.msdn.com/b/clrteam/
video Using Managed Profile Guided Optimization on a .NET App
Problems .NET Framework Install Size Difficult Setup Authoring Managed Metro style app performance
Solution: Reduce NGened assemblies .NET 3.5 .Net 3.5 .Net 4.5 .NET 4.5 .NET 3.5 .NET 4.5 Full .NET Framework NGened Frequent Set NGened
Classic NGen model App Run • Native Images Created • Native Images Used • Native Images Removed App Install App Uninstall
Automatic NGen model App Execute (MyApp.exe) App Execute App Execute Native Image Cache Assembly Image Usage Logs MyApp.ni.exe MyApp.exe OtherApp.ni.exe Auto Ngen Maintenance Task
Automatic NGen • Windows 8 only • .NET 3.5 – Framework Only • .NET 4.5 • Desktop app – Only assemblies in the GAC • Metro style app – All assemblies eligible
Problems Startup matters JITing takes time Unused resources
Multi-Core Background JITPerformance: Improves startup time (Desktop apps) First Launch Subsequent Launch Executed Methods Profile
Multi-Core Background JITApps and Hosts need to opt-in • using System.Runtime; • public static void Main(string[] args) • { • // Security Critical APIs • ProfileOptimization.SetProfileRoot(Config.GetAppPath); • ProfileOptimization.StartProfile("App1_Startup.prof"); • }
~10% startup time improvementAutomatically Enabled in ASP.net and Silverlight 5 Applications
Re-JIT No-restart production monitoring
Problems Production monitoring Instrumentation adds overhead Requires app restart LEARN MORE (792) Advanced IntelliTrace and using IntelliTrace in Production with Visual Studio 11
Instrumenting code with profiler • .method private hidebysig instance void InitiateTransaction() cil managed • { • .maxstack 8 • ldstr"TxnsInProgress" • call void ProductionMonitoring::IncrementTelemetry(string)ldarg.0 • newobjinstance voidCustomTransaction::.ctor() • stfldclass CustomTransaction App::m_CurrentTxn • ldarg.0 • ldfldclass CustomTransaction App::m_CurrentTxn • ldarg.0 • ldfldobjectApp::m_CurrentEnvironment • callvirtinstance void CustomTransaction::Initialize(object) • ret • }
Production MonitoringToday (.NET 4) Process start Process restart Process restart Instrumentation Problem detected Instrumentation Diagnose Instrumentation App runs
Re-JIT code • ICorProfilerInfo::SetEventMask(COR_PRF_ENABLE_REJIT • | COR_PRF_DISABLE_ALL_NGEN_IMAGES); • HRESULT ICorProfilerInfo4::RequestReJIT(ULONG cFunctions, • ModuleIDmoduleIds[], • mdMethodDefmethodIds[]); • HRESULT ICorProfilerCallback4:GetReJITParameters( • ModuleIDmoduleId, • mdMethodDefmethodId, • ICorProfilerFunctionControl*pFunctionControl); • HRESULT ICorProfilerFunctionControl::SetILFunctionBody( • LPCBYTE pbNewIL, ULONG cbNewIL);
Managed Profile Guided Optimizations are available for .NET Apps
“For more information” Slide RELATED SESSIONS DOCUMENTATION & ARTICLES CLR Team Blog: http://blogs.msdn.com/b/clrteam/ (TOOL-834T) What's new in .NET Framework 4.5 (TOOL-930C) A .NET developer's view of Windows 8 app development [chalk talk] (TOOL-810T) Async made simple in Windows 8, with C# and Visual Basic (TOOL-792T) Advanced IntelliTrace in production with Visual Studio 11
thank you Feedback and questions http://forums.dev.windows.com Session feedbackhttp://bldw.in/SessionFeedback
© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista 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.