• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
.NET Garbage Collection Performance Tips
 

.NET Garbage Collection Performance Tips

on

  • 4,951 views

In this presentation we review the basics of how the .NET garbage collector operates, and then tackle some best practices that can make the performance of your CLR-based applications improve ...

In this presentation we review the basics of how the .NET garbage collector operates, and then tackle some best practices that can make the performance of your CLR-based applications improve considerably. For example, we look at garbage collection flavors (server GC, background GC, and others), large object allocations, and finalization. We also review ways to track object allocations and even resolve memory leaks using the PerfView tool.

Statistics

Views

Total Views
4,951
Views on SlideShare
3,073
Embed Views
1,878

Actions

Likes
1
Downloads
9
Comments
0

23 Embeds 1,878

http://blogs.microsoft.co.il 1227
http://cloud.feedly.com 205
http://feeds.feedburner.com 204
http://dotnet.dzone.com 87
http://www.newsblur.com 47
http://feedreader.com 30
http://inoreader.com 17
http://newsblur.com 10
http://www.inoreader.com 9
http://reader.aol.com 6
http://lanyrd.com 6
http://www.feedspot.com 6
http://digg.com 5
http://feedly.com 5
http://smashingreader.com 3
http://webcache.googleusercontent.com 2
http://www.dzone.com 2
http://tiriss.com 2
http://rss.benmcevoy.com.au 1
http://subscribe.ru 1
http://reader.inthemail.org 1
http://feedproxy.google.com 1
http://www.hanrss.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    .NET Garbage Collection Performance Tips .NET Garbage Collection Performance Tips Presentation Transcript

    • Sasha Goldshtein CTO Sela Group @goldshtn blog.sashag.net Garbage Collection Performance Tips
    • www.devconnections.com GARBAGE COLLECTION PERFORMANCE TIPS WHY THIS TALK?  The .NET GC is a complex beast  Many performance optimizations over the years  Still many ways to shoot yourself in the foot Mark and Sweep Generations LOH Fragmentation Hoarding Segments Finalization Background GC VMMap PerfView Server GC 2
    • www.devconnections.com GARBAGE COLLECTION PERFORMANCE TIPS REFRESHER: TRACING GC .NET GC is not based on reference counting GC starts from roots and marks reachable objects as “live” The rest of the heap is swept as garbage Usually holes are compacted and objects are moved around Allocations are very cheap 3
    • www.devconnections.com GARBAGE COLLECTION PERFORMANCE TIPS PROBLEMS? Naïve implementation blocks mutators Result: very long application pauses 4
    • www.devconnections.com GARBAGE COLLECTION PERFORMANCE TIPS GC FLAVORS CLR 2.0 Workstation GC •Concurrent, non- concurrent Server GC •Parallel GC CLR 4.0 Background workstation GC CLR 4.5 Concurrent and background server GC 5
    • www.devconnections.com GARBAGE COLLECTION PERFORMANCE TIPS GENERATIONS  Full GC is slow and very inefficient – most objects are live  New objects die quickly, old objects die hard  Divide the heap into regions, enabling partial collections  Tricky to deal with cross-generation references  Special area for large objects (>85K) 6
    • www.devconnections.com GARBAGE COLLECTION PERFORMANCE TIPS MEASUREMENT Profile apps for allocations, not just time Look for large allocations, long-lived objs Pool temporary large objects 7
    • www.devconnections.com GARBAGE COLLECTION PERFORMANCE TIPS GC AND VIRTUAL MEMORY Windows VirtualAlloc has 64KB granularity in user-mode CLR allocates consecutive 16MB-64MB segments (x86) of memory On x86, easy to fragment the address space VMMap to detect, x64/VM hoarding to fix 8
    • www.devconnections.com GARBAGE COLLECTION PERFORMANCE TIPS FINALIZATION  Finalizer (cleanup) runs automatically after object becomes unreachable  Performance problems and bugs:  Allocation/finalization rate  Race conditions, deadlocks  The finalizer may run while a method is still executing on an instance 9
    • www.devconnections.com GARBAGE COLLECTION PERFORMANCE TIPS CONCLUSIONS Minimize the number and size of allocations Strive to quickly kill temporary objects Pool temporary large objects Don’t use finalization. Just don’t 10
    • www.devconnections.com GARBAGE COLLECTION PERFORMANCE TIPS ADDITIONAL REFERENCES
    • www.devconnections.com GARBAGE COLLECTION PERFORMANCE TIPS THANK YOU! Sasha Goldshtein @goldshtn sashag@sela.co.il blog.sashag.net 12