This presentation: Sasha GoldshteinCTO, Sela Group [email protected] Garbage Collection...
-
Upload
austen-carson -
Category
Documents
-
view
217 -
download
2
Transcript of This presentation: Sasha GoldshteinCTO, Sela Group [email protected] Garbage Collection...
This presentation: http://s.sashag.net/gctipsLT
Sasha Goldshtein CTO, Sela Groupblog.sashag.net @goldshtn
.NET Garbage Collection Performance Tips
This presentation: http://s.sashag.net/gctipsLT
Why This Talk?The .NET GC is a complex beastMany performance optimizations over the yearsStill many ways to shoot yourself in the foot
Mark and Sweep Generations LOHFragmentation Hoarding
Segments Finalization Background GC
VMMap PerfView Server GC
This presentation: http://s.sashag.net/gctipsLT
Refresher: Tracing GCGC starts from roots and marks reachable objects as “live”The rest of the heap is swept as garbageUsually holes are compacted and objects are moved aroundAllocations are very cheap
This presentation: http://s.sashag.net/gctipsLT
Problems?Naïve implementation blocks mutatorsResult: very long application pauses
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 APIGC notifications API
CLR 4.0
Background workstation GC
CLR 4.5
Concurrent and background server GC
CLR 4.5.1
LOH compaction API
This presentation: http://s.sashag.net/gctipsLT
Demo
GC Flavors
This presentation: http://s.sashag.net/gctipsLT
GenerationsFull GC is slow and very inefficientNew objects die quickly, old objects die hardDivide the heap into regions, enabling partial collectionsSpecial area for large objects
This presentation: http://s.sashag.net/gctipsLT
Measurement and Improvement
Profile apps for allocations, not just timeLook for large allocations, long-lived objectsPool temporary large objectsUse value types when possible
This presentation: http://s.sashag.net/gctipsLT
Demo
Reducing GC Pressure
This presentation: http://s.sashag.net/gctipsLT
GC and Virtual MemoryVirtualAlloc has 64KB granularity in user-mode
CLR allocates consecutive 16MB-64MB segments (x86) of memoryOn x86, easy to fragment the address space
This presentation: http://s.sashag.net/gctipsLT
Demo
VM Fragmentation
This presentation: http://s.sashag.net/gctipsLT
FinalizationFinalizer (cleanup) runs automatically after object becomes unreachable
This presentation: http://s.sashag.net/gctipsLT
Finalization IssuesAllocating faster than can possibly finalizeRace conditions, deadlocksThe finalizer may run while a method is still executing on an instance
This presentation: http://s.sashag.net/gctipsLT
Demo
Finalization
This presentation: http://s.sashag.net/gctipsLT
tips
Conclusions
• Measure early• Measure often• Measure again
Minimize the number and size of allocationsStrive to quickly kill temporary objectsPool temporary large objectsRely on Dispose() rather than finalization
This presentation: http://s.sashag.net/gctipsLT
Additional References
This presentation: http://s.sashag.net/gctipsLT
Questions
This presentation: http://s.sashag.net/gctipsLT
Sasha Goldshtein This presentation:blog.sashag.net s.sashag.net/gctipsLT@goldshtn
Thank You!