Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft...
-
Upload
antonia-gaines -
Category
Documents
-
view
217 -
download
0
Transcript of Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft...
![Page 1: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/1.jpg)
Lessons in Extreme .NET Performance
Ben WatsonPrincipal Software EngineerShared Platform Group, Application Services Group, MicrosoftAuthor, Writing High-Performance .NET Code
![Page 2: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/2.jpg)
![Page 3: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/3.jpg)
![Page 4: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/4.jpg)
Why Managed Code?
![Page 5: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/5.jpg)
Benefits of .NET
Isolation and safetyEasy testingDebuggingCode is easy to write*
![Page 6: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/6.jpg)
GC JIT 3rd Party Code People Factors
![Page 7: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/7.jpg)
Garbage Collection
Stops your program DEAD
![Page 8: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/8.jpg)
The Threat
![Page 9: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/9.jpg)
It’s very easy to build a system that spends an extraordinary amount of time in GC.
This is not inherent to the CLR!
![Page 10: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/10.jpg)
It is impossible to build a low-latency, high-performance server without taking
GC into account from the beginning.
![Page 11: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/11.jpg)
It is a myth that you can’t control the GC – you do so by controlling allocations.
![Page 12: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/12.jpg)
You need to understand the inner workings of the GC, just like you would any memory allocator.
![Page 13: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/13.jpg)
Generational GC in 30 seconds
![Page 14: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/14.jpg)
Gen2 Gen1 Gen0
Allocation point
![Page 15: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/15.jpg)
Lessons Learned
![Page 16: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/16.jpg)
The One Rule:Objects must die in a gen0 GC
- or –They must live forever in gen2.
![Page 17: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/17.jpg)
You will usually want to optimize for as little memory allocation as possible.
![Page 18: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/18.jpg)
The cost of a GC is proportional to the number of surviving objects.
![Page 19: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/19.jpg)
Consider pooling for objects with a long or unknown lifetime.
![Page 20: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/20.jpg)
Pool everything in the large object heap.
![Page 21: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/21.jpg)
github.com/Microsoft/Microsoft.IO.RecyclableMemoryStream
![Page 22: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/22.jpg)
GC work never stops
![Page 23: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/23.jpg)
Just In Time Compilation
Just in time to SLOW YOU DOWN
![Page 24: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/24.jpg)
Should you worry about JIT?
![Page 25: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/25.jpg)
The Threat
![Page 26: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/26.jpg)
Reduce the amount of Code
![Page 27: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/27.jpg)
Use the latest .NET
![Page 28: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/28.jpg)
Warmup Code
![Page 29: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/29.jpg)
Manual JITRuntimeHelpers.PrepareMethod
![Page 30: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/30.jpg)
NGEN
![Page 31: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/31.jpg)
A little of this, a little of that…
![Page 32: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/32.jpg)
3rd Party Code
Trust No One
![Page 33: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/33.jpg)
My Code vs. Your Code
![Page 34: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/34.jpg)
![Page 35: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/35.jpg)
![Page 36: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/36.jpg)
Joking aside…
![Page 37: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/37.jpg)
The Threat
![Page 38: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/38.jpg)
The Framework Class Library
![Page 39: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/39.jpg)
How would you implement Enum.HasFlag()?
![Page 40: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/40.jpg)
![Page 41: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/41.jpg)
![Page 42: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/42.jpg)
![Page 43: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/43.jpg)
Read the Source
![Page 44: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/44.jpg)
Default collection sizes
![Page 45: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/45.jpg)
Quiz: How many different XML serialization options ship with .NET?
![Page 46: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/46.jpg)
XmlTextReader
XmlValidatingReader
XDocument
XPathNavigatorXPathDocument
LINQ-to-XML
DataContractSerializer
XmlSerializer
![Page 47: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/47.jpg)
Methods that throw exceptions in normal conditions.
![Page 48: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/48.jpg)
Static analysis
![Page 49: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/49.jpg)
FxCop
Stupid String Tricks: ToLower, ToUpper, Format, Join
![Page 50: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/50.jpg)
FxCop
Stupid String Tricks: ToLower, ToUpper, Format, Join
Large Static Allocations (>85K go on LOH)
![Page 51: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/51.jpg)
FxCop
Stupid String Tricks: ToLower, ToUpper, Format, Join
Large Static Allocations (>85K go on LOH)
Prevent finalizers
![Page 52: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/52.jpg)
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
![Page 53: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/53.jpg)
FxCop
Stupid String Tricks: ToLower, ToUpper, Format, Join
Large Static Allocations (>85K go on LOH)
Prevent finalizersWarn against LINQ
Force use of pooling APIs for some types
![Page 54: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/54.jpg)
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)
![Page 55: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/55.jpg)
People Factors
(No, you can’t actually use a hammer and sword.)
![Page 56: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/56.jpg)
![Page 57: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/57.jpg)
![Page 58: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/58.jpg)
You must train people
![Page 59: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/59.jpg)
Code does not exist in a vacuum
![Page 60: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/60.jpg)
Understand the Tradeoffs
![Page 61: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/61.jpg)
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
![Page 62: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/62.jpg)
It is impossible to build a low-latency, high-performance server without taking
GC into account from the beginning.
![Page 63: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/63.jpg)
Performance is a Feature
![Page 64: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/64.jpg)
GC JIT 3rd Party Code People Factors
![Page 65: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/65.jpg)
![Page 66: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/66.jpg)
Want to know more?
.NET Performance Deep-Dive WorkshopThursday, 9am, Garden A
![Page 67: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/67.jpg)
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
![Page 68: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/68.jpg)
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
![Page 69: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/69.jpg)
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
![Page 70: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/70.jpg)
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-micro
benchmarks.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)
![Page 71: Ben Watson Principal Software Engineer Shared Platform Group, Application Services Group, Microsoft Author, Writing High-Performance.NET Code.](https://reader034.fdocuments.in/reader034/viewer/2022051401/5697bf931a28abf838c8fa95/html5/thumbnails/71.jpg)
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