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

The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?Mark Billinghurst
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxFIDO Alliance
 
Revolutionizing SAP® Processes with Automation and Artificial Intelligence
Revolutionizing SAP® Processes with Automation and Artificial IntelligenceRevolutionizing SAP® Processes with Automation and Artificial Intelligence
Revolutionizing SAP® Processes with Automation and Artificial IntelligencePrecisely
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewDianaGray10
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceSamy Fodil
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandIES VE
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxFIDO Alliance
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxMasterG
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Skynet Technologies
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch TuesdayIvanti
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityVictorSzoltysek
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingScyllaDB
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfdanishmna97
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Hiroshi SHIBATA
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPTiSEO AI
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsLeah Henrickson
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTopCSSGallery
 

Recently uploaded (20)

The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Revolutionizing SAP® Processes with Automation and Artificial Intelligence
Revolutionizing SAP® Processes with Automation and Artificial IntelligenceRevolutionizing SAP® Processes with Automation and Artificial Intelligence
Revolutionizing SAP® Processes with Automation and Artificial Intelligence
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 

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