Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.

Slides:



Advertisements
Similar presentations
.NET Framework Overview Pingping Ma Nov 16 th, 2006.
Advertisements

This presentation: Sasha GoldshteinCTO, Sela Group Garbage Collection Performance Tips.
The Microsoft View: Module 1: Getting Started. Copyright Course 2559B, Introduction to Visual Basic®.NET Programming with Microsoft®.NET. Lecture 1 Microsoft.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
Reasons to study concepts of PL
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared.
DotNET A Developer’s Perspective Mike Litzkow University of Wisconsin - MadisonOne.
How to Build High Performing.NET Applications Vance Morrison.NET Performance Architect July 2009.
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Intro to dot Net Dr. John Abraham UTPA – Fall 09 CSCI 3327.
CLR: Garbage Collection Inside Out
Microsoft Visual Basic 2005 CHAPTER 1 Introduction to Visual Basic 2005 Programming.
A Free sample background from © 2001 By Default!Slide 1.NET Overview BY: Pinkesh Desai.
Overview of Microsoft.Net and Vb.Net ITSE 2349 Spring 2002 Material from Microsoft.Net an Overview for ACC faculty by Stuart Laughton and Introduction.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Chocolate Bar! luqili. Milestone 3 Speed 11% of final mark 7%: path quality and speed –Some cleverness required for full marks –Implement some A* techniques.
Introduction to .Net Framework
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Database Design for DNN Developers Sebastian Leupold.
1 8/29/05CS360 Windows Programming Professor Shereen Khoja.
Architecture of.NET Framework .NET Framework ٭ Microsoft.NET (pronounced “dot net”) is a software component that runs on the Windows operating.
Module 1: Introduction to C# Module 2: Variables and Data Types
.NET Overview. 2 Objectives Introduce.NET –overview –languages –libraries –development and execution model Examine simple C# program.
C# A 1 CSC 298 Introduction to C#. C# A 2 What to expect in this class  Background: knowledge of an object oriented language of the C++, Java, … family.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
What is.NET?.NET is a "revolutionary new platform, built on open Internet protocols and standards, with tools and services that meld computing and communications.
Lesley Bross, August 29, 2010 ArcGIS 10 add-in glossary.
ASP.NET  ASP.NET is a web development platform, which provides a programming model, a comprehensive software infrastructure and various services required.
C# Overview and Features. Content I.History of C# II.Architecture III.How to install IV.Features V.Code Sample VI.Microsoft.NET Platform VII.Why use C#
StyleCop Breaking down the barriers to entry Gary Ewan Park Twitter: Blog:
File I/O Applied Component-Based Software Engineering File I/O CSE 668 / ECE 668 Prof. Roger Crawfis.
Lecture 1 Programming in C# Introducing C# Writing a C# Program.
Managed C++. Objectives Overview to Visual C++.NET Concepts and architecture Developing with Managed Extensions for C++ Use cases Managed C++, Visual.
Visual Studio 2005 Team System: Building Robust & Reliable Software Tejasvi Kumar Technology Specialist - VSTS Microsoft Corporation
Component-Based Software Engineering Introduction to.NET Paul Krause.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
DAT 379 XML Today And Tomorrow Mark Fussell Lead Program Manager Microsoft Corporation.
COMP 121 Week 1: Testing and Debugging. Testing Program testing can be used to show the presence of bugs, but never to show their absence! ~ Edsger Dijkstra.
tom perkins1 XML Web Services -.NET FRAMEWORK – Part 1 CHAPTER 1.1 – 1.3.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/6/2006 Lecture 24 – Profilers.
Eagle: Maturation and Evolution 17th Annual Tcl Conference Joe Mistachkin.
Writing faster managed code Claudio Caldato Program Manager CLR Performance Team.
Module 1: Getting Started. Introduction to.NET and the.NET Framework Exploring Visual Studio.NET Creating a Windows Application Project Overview Use Visual.
1 EPICS Bus Errors & Power PC u VME Bus Error can generate a Machine Check Exception (MCE) u The WRS mv2700 BSP doesn’t have code to do this u Write cycles.
Development and Debugging Tools for Windows Phone 7 Series Cullen Waters Software Development Engineer II Advanced Technology Group, Microsoft Corporation.
Intro to dot Net Dr. John Abraham UTPA CSCI 3327.
PRIOR TO WEB SERVICES THE OTHER TECHNOLOGIES ARE:.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Microsoft .NET A platform that can be used for building and running windows and web applications such that the software is platform and device-independent.
Getting Started with.NET Getting Started with.NET/Lesson 1/Slide 1 of 31 Objectives In this lesson, you will learn to: *Identify the components of the.NET.
Object Oriented Software Development 4. C# data types, objects and references.
Tips & Tricks: Writing Performant Managed Code Rico Mariani FUNL04 Performance Architect Microsoft Corporation.
Common Language Runtime Introduction  The common language runtime is one of the most essential component of the.Net Framework.  It acts.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
Text Introduction to.NET Framework. CONFIDENTIAL Agenda .NET Training – Purpose  What is.NET?  Why.NET?  Advantages  Architecture  Components: CLR,
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Lecture #20: Profiling NetBeans Profiler 6.0.
ITP 109 Week 2 Trina Gregory Introduction to Java.
Boris Jabes Program Manager Visual C++ Microsoft Corporation.
.NET Garbage Collection Performance Tips Sasha Goldshtein | SELA Group.
Source Code Inspection and Software Reuse
More Sophisticated Behavior
CLR MD A New Swiss Army Knife tool for Advanced Debugging
Module 1: Getting Started
PerfView Measure and Improve Your App’s Performance for Free
Introduction to .NET By : Mr. V. D. Panchal Content :
.Net Framework Details Imran Rashid CTO at ManiWeber Technologies.
Module 10: Implementing Managed Code in the Database
Eagle: Maturation and Evolution
IS 135 Business Programming
Presentation transcript:

Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code

Why Managed Code?

Benefits of.NET Isolation and safety Easy testing Debugging Code is easy to write*

GCJIT3 rd Party CodePeople Factors

Garbage Collection Stops your program DEAD

The Threat

It’s very easy to build a system that spends an extraordinary amount of time in GC. This is not inherent to the CLR!

It is impossible to build a low-latency, high-performance server without taking GC into account from the beginning.

It is a myth that you can’t control the GC – you do so by controlling allocations.

You need to understand the inner workings of the GC, just like you would any memory allocator.

Generational GC in 30 seconds

Lessons Learned

You will usually want to optimize for as little memory allocation as possible.

The cost of a GC is proportional to the number of surviving objects.

Consider pooling for objects with a long or unknown lifetime.

Pool everything in the large object heap.

github.com/Microsoft/Microsoft.IO.RecyclableMemoryStream

GC work never stops

Just In Time Compilation Just in time to SLOW YOU DOWN

Should you worry about JIT?

The Threat

Reduce the amount of Code

Use the latest.NET

Warmup Code

Manual JIT RuntimeHelpers.PrepareMethod

NGEN

A little of this, a little of that…

3 rd Party Code Trust No One

My Code vs. Your Code

Joking aside…

The Threat

The Framework Class Library

How would you implement Enum.HasFlag()?

Read the Source

Default collection sizes

Quiz: How many different XML serialization options ship with.NET?

XmlTextReader XmlValidatingReader XDocument XPathNavigator XPathDocument LINQ-to-XML DataContractSerializer XmlSerializer

Methods that throw exceptions in normal conditions.

Static analysis

FxCop Stupid String Tricks: ToLower, ToUpper, Format, Join

FxCop Stupid String Tricks: ToLower, ToUpper, Format, Join Large Static Allocations (>85K go on LOH)

FxCop Stupid String Tricks: ToLower, ToUpper, Format, Join Large Static Allocations (>85K go on LOH) Prevent finalizers

FxCop Stupid String Tricks: ToLower, ToUpper, Format, Join Large Static Allocations (>85K go on LOH) Force use of pooling APIs for some types Prevent finalizers

FxCop Stupid String Tricks: ToLower, ToUpper, Format, Join Large Static Allocations (>85K go on LOH) Prevent finalizers Warn against LINQ Force use of pooling APIs for some types

It looks like you’re writing awful, poorly performing code. Would you like to stop already? Projects like RoslynClrHeapAllocationAnalyzer This is the future… (note: Clippy not actually included)

People Factors (No, you can’t actually use a hammer and sword.)

You must train people

Code does not exist in a vacuum

Understand the Tradeoffs

Benefits Memory safety Type safety Fast allocations Debugging is MUCH better Better static code analysis Code locality Costs JIT Garbage Collection Bounds checking, type checking Training Hidden code

It is impossible to build a low-latency, high-performance server without taking GC into account from the beginning.

Performance is a Feature

GCJIT3 rd Party CodePeople Factors

Resources Books Writing High-Performance.NET Code Book Site – Can get the following for free: Book Site Intro, Chapter 1 – general measurement guidelines, tools, how to use Windbg and PerfView (and others) Chapter 5 – Performance Considerations of Class Design and General CodingPerformance Considerations of Class Design and General Coding Advanced.NET Debugging by Mario Hewardt Advanced.NET Debugging Article:.NET memory allocation details.NET memory allocation details

Resources Vance Morrison’s CLR Inside Out columns on performance: Measure Early and Often for Performance, Parts 1 & Interface Dispatch: SOS command reference Windbg command reference

Tools Reflector, ILSpy, ILDASM – tools to convert compiled binaries into readable code. Essential for understanding how 3 rd -party code (including the FCL) works. FxCop Performance rules are limited, but useful Warns about things like multiple casts, Equals() on value types, empty finalizers, etc. Lots of other style and correctness rules Get in the habit of running these as part of your build DON’T get in the habit of issuing exceptions for rule violations -- just fix the issue if possible

Tools MeasureIt Small, simple tool for running microbenchmarks on the.Net framework microbenchmarks.aspx microbenchmarks.aspx PerfView ETW event analyzer with clever views (like a CPU profiler) Can analyze both CPU and memory events Can tell you who is allocating memory, who owns memory, who is allocating on the LOH How often are GCs? How long do they last? Exceptions being thrown and handled Jitting events Anything else that’s an ETW event (which is most things)

Tools Windbg & SOS The best way in many cases to understand what’s really going on SOS is the managed debugging extensions Comes with CLR, already setup to work with WinDbg in PHX See for SOS commandshttp://msdn.microsoft.com/en-us/library/bb aspx Getting started: Attach to your process.loadby sos clr !bpmd program.exe Namespace.Type.Method g !ClrStack