SlideShare a Scribd company logo
1 of 74
Ben Watson
Principal Software Engineer
Shared Platform Group, Application Services Group, Microsoft
Author, Writing High-Performance .NET Code
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
http://www.infoq.com/presentations
/bing-net-performance
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Presented at QCon San Francisco
www.qconsf.com
Why Managed Code?
Benefits of .NET
Isolation and safety
Easy testing
Debugging
Code is easy to write*
GC JIT 3rd Party Code People 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
Gen2 Gen1 Gen0
Allocation
point
Lessons Learned
Objects must die in a gen0 GC
- or –
They must live forever in gen2.
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…
3rd 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
Understand the Tradeoffs
It is impossible to build a low-latency, high-
performance server without taking GC into
account from the beginning.
Performance is a Feature
GC JIT 3rd Party Code People Factors
Want to know more?
Thursday, 9am, Garden A
Resources
• Books
• Writing High-Performance .NET Code
• Book Site – Can get the following for free:
• Intro, Chapter 1 – general measurement guidelines, tools, how to use Windbg
and PerfView (and others)
• Chapter 5 – Performance Considerations of Class Design and General Coding
• Advanced .NET Debugging by Mario Hewardt
• Article: .NET memory allocation details
Resources
• Vance Morrison’s CLR Inside Out columns on performance: Measure Early and Often for
Performance, Parts 1 & 2
• http://msdn.microsoft.com/en-us/magazine/cc500596.aspx
• http://msdn.microsoft.com/en-us/magazine/cc507639.aspx
• Interface Dispatch: http://blogs.msdn.com/b/vancem/archive/2006/03/13/550529.aspx
• SOS command reference
• http://msdn.microsoft.com/en-us/library/bb190764.aspx
• Windbg command reference
• http://windbg.info/doc/1-common-cmds.html
Tools
• Reflector, ILSpy, ILDASM – tools to convert compiled binaries into readable code. Essential
for understanding how 3rd-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
• http://blogs.msdn.com/b/vancem/archive/2009/02/06/measureit-update-tool-for-doing-
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 http://msdn.microsoft.com/en-us/library/bb190764.aspx for SOS commands
• Getting started:
• Attach to your process
• .loadby sos clr
• !bpmd program.exe Namespace.Type.Method
• g
• !U @rip
• !ClrStack
Watch the video with slide synchronization on
InfoQ.com!
http://www.infoq.com/presentations/bing-net-
performance

More Related Content

Viewers also liked

How to Analyze Reports in Jmeter
How to Analyze Reports in JmeterHow to Analyze Reports in Jmeter
How to Analyze Reports in JmeterViviana Lesmes
 
Continuous integration and delivery for java based web applications
Continuous integration and delivery for java based web applicationsContinuous integration and delivery for java based web applications
Continuous integration and delivery for java based web applicationsSunil Dalal
 
Docker Overview - Rise of the Containers
Docker Overview - Rise of the ContainersDocker Overview - Rise of the Containers
Docker Overview - Rise of the ContainersRyan Hodgin
 
Continuous Integration using Docker & Jenkins
Continuous Integration using Docker & JenkinsContinuous Integration using Docker & Jenkins
Continuous Integration using Docker & JenkinsB1 Systems GmbH
 
Chef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of ChefChef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of ChefChef Software, Inc.
 
Interpreting Performance Test Results
Interpreting Performance Test ResultsInterpreting Performance Test Results
Interpreting Performance Test ResultsEric Proegler
 
Jenkins Docker
Jenkins DockerJenkins Docker
Jenkins DockerAlex Soto
 
Chef for DevOps - an Introduction
Chef for DevOps - an IntroductionChef for DevOps - an Introduction
Chef for DevOps - an IntroductionSanjeev Sharma
 
Reduce DevOps Friction with Docker & Jenkins by Andy Pemberton, Cloudbees
Reduce DevOps Friction with Docker & Jenkins by Andy Pemberton, CloudbeesReduce DevOps Friction with Docker & Jenkins by Andy Pemberton, Cloudbees
Reduce DevOps Friction with Docker & Jenkins by Andy Pemberton, CloudbeesDocker, Inc.
 
Jenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated DeploymentJenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated DeploymentDan Stine
 
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and ComposeDockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and ComposeDocker, Inc.
 
CLIF meets Jenkins: performance testing in continuous integration, or more......
CLIF meets Jenkins: performance testing in continuous integration, or more......CLIF meets Jenkins: performance testing in continuous integration, or more......
CLIF meets Jenkins: performance testing in continuous integration, or more......OW2
 
Docker introduction
Docker introductionDocker introduction
Docker introductiondotCloud
 
Scaling Jenkins with Docker and Kubernetes
Scaling Jenkins with Docker and KubernetesScaling Jenkins with Docker and Kubernetes
Scaling Jenkins with Docker and KubernetesCarlos Sanchez
 
Connecting With the Disconnected
Connecting With the DisconnectedConnecting With the Disconnected
Connecting With the DisconnectedChris Wejr
 
Guided Reading: Making the Most of It
Guided Reading: Making the Most of ItGuided Reading: Making the Most of It
Guided Reading: Making the Most of ItJennifer Jones
 

Viewers also liked (17)

How to Analyze Reports in Jmeter
How to Analyze Reports in JmeterHow to Analyze Reports in Jmeter
How to Analyze Reports in Jmeter
 
Continuous integration and delivery for java based web applications
Continuous integration and delivery for java based web applicationsContinuous integration and delivery for java based web applications
Continuous integration and delivery for java based web applications
 
Docker Overview - Rise of the Containers
Docker Overview - Rise of the ContainersDocker Overview - Rise of the Containers
Docker Overview - Rise of the Containers
 
How to start performance testing project
How to start performance testing projectHow to start performance testing project
How to start performance testing project
 
Continuous Integration using Docker & Jenkins
Continuous Integration using Docker & JenkinsContinuous Integration using Docker & Jenkins
Continuous Integration using Docker & Jenkins
 
Chef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of ChefChef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of Chef
 
Interpreting Performance Test Results
Interpreting Performance Test ResultsInterpreting Performance Test Results
Interpreting Performance Test Results
 
Jenkins Docker
Jenkins DockerJenkins Docker
Jenkins Docker
 
Chef for DevOps - an Introduction
Chef for DevOps - an IntroductionChef for DevOps - an Introduction
Chef for DevOps - an Introduction
 
Reduce DevOps Friction with Docker & Jenkins by Andy Pemberton, Cloudbees
Reduce DevOps Friction with Docker & Jenkins by Andy Pemberton, CloudbeesReduce DevOps Friction with Docker & Jenkins by Andy Pemberton, Cloudbees
Reduce DevOps Friction with Docker & Jenkins by Andy Pemberton, Cloudbees
 
Jenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated DeploymentJenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated Deployment
 
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and ComposeDockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
 
CLIF meets Jenkins: performance testing in continuous integration, or more......
CLIF meets Jenkins: performance testing in continuous integration, or more......CLIF meets Jenkins: performance testing in continuous integration, or more......
CLIF meets Jenkins: performance testing in continuous integration, or more......
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
Scaling Jenkins with Docker and Kubernetes
Scaling Jenkins with Docker and KubernetesScaling Jenkins with Docker and Kubernetes
Scaling Jenkins with Docker and Kubernetes
 
Connecting With the Disconnected
Connecting With the DisconnectedConnecting With the Disconnected
Connecting With the Disconnected
 
Guided Reading: Making the Most of It
Guided Reading: Making the Most of ItGuided Reading: Making the Most of It
Guided Reading: Making the Most of It
 

More from C4Media

Streaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoStreaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoC4Media
 
Next Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileNext Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileC4Media
 
Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020C4Media
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsC4Media
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No KeeperC4Media
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like OwnersC4Media
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaC4Media
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideC4Media
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDC4Media
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine LearningC4Media
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at SpeedC4Media
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsC4Media
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsC4Media
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleC4Media
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeC4Media
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereC4Media
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing ForC4Media
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data EngineeringC4Media
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreC4Media
 

More from C4Media (20)

Streaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoStreaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live Video
 
Next Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileNext Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy Mobile
 
Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No Keeper
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like Owners
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate Guide
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 

Recently uploaded

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Recently uploaded (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Lessons in Extreme .NET Performance

  • 1. Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance .NET Code
  • 2. InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /bing-net-performance
  • 3. Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide Presented at QCon San Francisco www.qconsf.com
  • 4.
  • 5.
  • 7. Benefits of .NET Isolation and safety Easy testing Debugging Code is easy to write*
  • 8. GC JIT 3rd Party Code People Factors
  • 11. It’s very easy to build a system that spends an extraordinary amount of time in GC. This is not inherent to the CLR!
  • 12. It is impossible to build a low-latency, high- performance server without taking GC into account from the beginning.
  • 13. It is a myth that you can’t control the GC – you do so by controlling allocations.
  • 14. You need to understand the inner workings of the GC, just like you would any memory allocator.
  • 15. Generational GC in 30 seconds
  • 18. Objects must die in a gen0 GC - or – They must live forever in gen2.
  • 19. You will usually want to optimize for as little memory allocation as possible.
  • 20. The cost of a GC is proportional to the number of surviving objects.
  • 21. Consider pooling for objects with a long or unknown lifetime.
  • 22. Pool everything in the large object heap.
  • 24. GC work never stops
  • 25. Just In Time Compilation Just in time to SLOW YOU DOWN
  • 26. Should you worry about JIT?
  • 28. Reduce the amount of Code
  • 32. NGEN
  • 33. A little of this, a little of that…
  • 35. My Code vs. Your Code
  • 36.
  • 37.
  • 41. How would you implement Enum.HasFlag()?
  • 42.
  • 43.
  • 44.
  • 47. Quiz: How many different XML serialization options ship with .NET?
  • 49. Methods that throw exceptions in normal conditions.
  • 51. FxCop Stupid String Tricks: ToLower, ToUpper, Format, Join
  • 52. FxCop Stupid String Tricks: ToLower, ToUpper, Format, Join Large Static Allocations (>85K go on LOH)
  • 53. FxCop Stupid String Tricks: ToLower, ToUpper, Format, Join Large Static Allocations (>85K go on LOH) Prevent finalizers
  • 54. 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
  • 55. 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
  • 56. 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)
  • 57. People Factors (No, you can’t actually use a hammer and sword.)
  • 58.
  • 59.
  • 60. You must train people
  • 61. Code does not exist in a vacuum
  • 64. It is impossible to build a low-latency, high- performance server without taking GC into account from the beginning.
  • 65. Performance is a Feature
  • 66. GC JIT 3rd Party Code People Factors
  • 67.
  • 68. Want to know more? Thursday, 9am, Garden A
  • 69. Resources • Books • Writing High-Performance .NET Code • Book Site – Can get the following for free: • Intro, Chapter 1 – general measurement guidelines, tools, how to use Windbg and PerfView (and others) • Chapter 5 – Performance Considerations of Class Design and General Coding • Advanced .NET Debugging by Mario Hewardt • Article: .NET memory allocation details
  • 70. Resources • Vance Morrison’s CLR Inside Out columns on performance: Measure Early and Often for Performance, Parts 1 & 2 • http://msdn.microsoft.com/en-us/magazine/cc500596.aspx • http://msdn.microsoft.com/en-us/magazine/cc507639.aspx • Interface Dispatch: http://blogs.msdn.com/b/vancem/archive/2006/03/13/550529.aspx • SOS command reference • http://msdn.microsoft.com/en-us/library/bb190764.aspx • Windbg command reference • http://windbg.info/doc/1-common-cmds.html
  • 71. Tools • Reflector, ILSpy, ILDASM – tools to convert compiled binaries into readable code. Essential for understanding how 3rd-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
  • 72. Tools • MeasureIt • Small, simple tool for running microbenchmarks on the .Net framework • http://blogs.msdn.com/b/vancem/archive/2009/02/06/measureit-update-tool-for-doing- 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)
  • 73. 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 http://msdn.microsoft.com/en-us/library/bb190764.aspx for SOS commands • Getting started: • Attach to your process • .loadby sos clr • !bpmd program.exe Namespace.Type.Method • g • !U @rip • !ClrStack
  • 74. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations/bing-net- performance