Download presentation
Presentation is loading. Please wait.
Published byTobias Carroll Modified over 8 years ago
1
Tips & Tricks: Writing Performant Managed Code Rico Mariani FUNL04 Performance Architect Microsoft Corporation
2
2 What’s New In Whidbey CLR? …and why should you be pleased? Some of my favorites…
3
3 More Sharing With NGen Possibly the largest single investment area for Whidbey NGen can drastically reduce private bytes Critical for library vendors Critical if multiple managed executables running concurrently Reduction translates almost directly into startup savings – both hot and cold
4
4 Advanced NGen Features Hard binding Use attributes to tell ngen about strong dependencies between assemblies Allows superior code generation with less “fixups” String Freezing Use attribute to indicate that ngen should include a GC segment that contains all of your string literals pre-created in your assembly Tastes even better with hard binding Set base addresses correctly Watch for relocated modules or all these savings disappear
5
5 Generics Eradicate your boxing issues with Generic collection classes Add strong typing without code duplication in many places Avoid the dark side – do not create types like crazy or the static cost of all those types will erase your savings Collections storing a total of about 500 objects will come out ahead
6
6 Enumerators And Foreach ArrayList implements IEnumerable in not the best possible way – can’t change due to backwards compatability The Generic collections such as List and Dictionary use a superior approach Most applications were not affected in the first place but if you were shy of using foreach in the past there’s really no reason to avoid it at all now Guilt-free foreach in Whidbey Guilt-free foreach in Whidbey
7
7 GC Keeps Getting Better Better heuristics can save much space especially in interactive applications Time-base criteria helps find idle cases Configure the GC without using expensive hosting APIs GC is unified so you can (e.g.) opt in to Server GC even on a workstation where that makes sense
8
8 Exceptions Improvements Since Beta2 much cheaper to throw exceptions – especially in deep stacks guidance is still to avoid exceptions on the main path Avoidance Use exception-free variations such as TryParse when failure is “normal” Provides return code based instead of throwing
9
9 Security Large performance effort on security in Whidbey Reduced cost of startup with better security XML parser Universally reduced cost of asserts Reduced cost of the most common demands (e.g. unmanaged code access, full trust, etc.) Faster paths through the interop system Generally "full trust" performance is excellent with very low throughput overhead
10
10 Reflection Whidbey includes a major overhaul caching policy greatly improved much more economical overall behavior Reflection data does not accumulate forever Useful new API's for getting just the data you need Access to information about a single method does not require fetching information about others “Token” based access methods give more direct access to the metadata
11
11 Profiling API Much more functional in Whidbey Additional callbacks to fully track object lifetime translate directly into better profilers for you CLRProfiler already taking advantage of these features Object inspection without needing a debugger Profilers can show function arguments etc. Sampling profilers supported Many simple profilers can be written to do special purpose checking for your application
12
12 Lots More! Threadpool: Adaptive thread injection Delegates: Dispatch is faster in Whidbey String: Comparisons by ordinal; hashing faster Cross App Domain calls: Up to 10x faster for simple types AddMemoryPressure: Informs the collector of unmanaged memory usage better decisions And that’s only what happened in the CLR… Many improvements in the framework too
13
13 Resources You can find my blog at http://blogs.msdn.com/ricom http://blogs.msdn.com/ricom I keep a bibliography of interesting articles at http://channel9.msdn.com/wiki/default.aspx/ Channel9.RicoM http://channel9.msdn.com/wiki/default.aspx/ Channel9.RicoM http://channel9.msdn.com/wiki/default.aspx/ Channel9.RicoM
14
14 Questions?
15
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.