Download presentation
Presentation is loading. Please wait.
Published byAusten Carson Modified over 9 years ago
1
This presentation: http://s.sashag.net/gctipsLT Sasha GoldshteinCTO, Sela Group blog.sashag.net@goldshtn.NET Garbage Collection Performance Tips
2
This presentation: http://s.sashag.net/gctipsLT 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 GenerationsLOH Fragmentation Hoarding Segments Finalization Background GC VMMap PerfView Server GC
3
This presentation: http://s.sashag.net/gctipsLT Refresher: Tracing GC 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
4
This presentation: http://s.sashag.net/gctipsLT Problems? Naïve implementation blocks mutators Result: very long application pauses
5
This presentation: http://s.sashag.net/gctipsLT.NET GC Evolution CLR 2.0 Workstation GC Concurrent, non- concurrent Server GC Parallel GC CLR 2.0 SP1 GC latency API GC notifications API CLR 4.0 Background workstation GC CLR 4.5 Concurrent and background server GC CLR 4.5.1 LOH compaction API
6
This presentation: http://s.sashag.net/gctipsLT Demo GC Flavors
7
This presentation: http://s.sashag.net/gctipsLT Generations Full GC is slow and very inefficient New objects die quickly, old objects die hard Divide the heap into regions, enabling partial collections Special area for large objects
8
This presentation: http://s.sashag.net/gctipsLT Measurement and Improvement Profile apps for allocations, not just time Look for large allocations, long-lived objects Pool temporary large objects Use value types when possible
9
This presentation: http://s.sashag.net/gctipsLT Demo Reducing GC Pressure
10
This presentation: http://s.sashag.net/gctipsLT GC and Virtual Memory VirtualAlloc has 64KB granularity in user-mode CLR allocates consecutive 16MB- 64MB segments (x86) of memory On x86, easy to fragment the address space
11
This presentation: http://s.sashag.net/gctipsLT Demo VM Fragmentation
12
This presentation: http://s.sashag.net/gctipsLT Finalization Finalizer (cleanup) runs automatically after object becomes unreachable
13
This presentation: http://s.sashag.net/gctipsLT Finalization Issues Allocating faster than can possibly finalize Race conditions, deadlocks The finalizer may run while a method is still executing on an instance
14
This presentation: http://s.sashag.net/gctipsLT Demo Finalization
15
This presentation: http://s.sashag.net/gctipsLT tips Conclusions Measure early Measure often Measure again Minimize the number and size of allocations Strive to quickly kill temporary objects Pool temporary large objects Rely on Dispose() rather than finalization
16
This presentation: http://s.sashag.net/gctipsLT Additional References
17
This presentation: http://s.sashag.net/gctipsLT Questions
18
This presentation: http://s.sashag.net/gctipsLT Sasha GoldshteinThis presentation: blog.sashag.nets.sashag.net/gctipsLT @goldshtn Thank You!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.