SlideShare a Scribd company logo
Performance in the .NET world. A developer’s perspectiveSorin Oboroceanu, Vlad BalanRomSoft, www.rms.roIaşi, May 4th 2010
AgendaString vs. StringBuilderSerializationReading XMLGarbage CollectionJITing2
String vs. StringBuilder3DEMO
Our Demo APPUses StackOverflow.com’s dataGroups users by locationDisplays user locations in a chartWill work in a client/server architectureHas performance issues 4
CollectionsGroupping dataList<T>LINQ to ObjectsDictionary<T,V>5DEMO
Client-Server communicationRetrieving all users on the clientGrouping dataList<T>LINQ to ObjectsDictionary<T,V>6DEMO
Client-Server communicationGrouping data on the serverList<T>LINQ to ObjectsDictionary<T,V>Retrieving only location-related data on the client7DEMO
Reading XMLDataSetXmlReaderLINQ to XMLXmlDocument8DEMO
Garbage CollectionWhy memory mattersGarbage CollectorCommon Memory IssuesDiagnosing Memory Problems 9
Why memory mattersInefficient use of memory can impactPerformanceStabilityScalabilityOther ApplicationsHidden problems in code can causeMemory LeaksExcessive memory usageUnnecessary performance overhead10
GC – Small Object Heap (SOH)11GCSmallObjectObjectA = new SmallObject(); SmallObjectObjectB = new SmallObject(); Global ObjectsSmall Object  HeapNext Object PointerObjectENext Object PointerStackObjectDStatic ObjectsNext Object PointerObjectCNext Object PointerObjectBObjectBNext Object PointerObjectAObjectARoot ReferenceNext Object PointerChild Reference
GC- Gen2LargeObjectObjectD= new LargeObject(); Global ObjectsFree space tableLarge Object  Heap42500016777216ObjectD572740094208182272Free spaceStackObjectCObjectCObjectBFree spaceObjectBObjectAObjectA1212
13GC - Gen 0GC - Gen 1GC - Gen 2Small Object  HeapGen 0Next Object PointerGlobal ObjectsObjectDObjectCNext Object PointerGen 1Static ObjectsStackObjectBGen 2ObjectARoot Reference
GC – Minimizing Overheadpublic class Test: IDisposable{  ~Test()  {	Cleanup (false);   }  private void Cleanup(boolcodeDispose)  {      if (codeDispose)      {	// dispose managed resources        }	// clean up unmanaged resources   }  public void Dispose()  {	Cleanup (true); GC.SuppressFinalize(this);  } }14
GC – Common Memory IssuesExcessive RAM FootprintApp allocates objects too early or for too long using more memory than neededCan affect other apps on the systemExcessive Temporary Object allocationGarbage Collection runs more frequentlyExecuting threads freeze during Garbage CollectionMemory LeaksOverlooked root references keep objects alive (Collections, array, session state, delegates/events)Incorrect or absent Finalization can cause resources leaks15
DEMO16
JITing17Consolestatic void WriteLine();static void WriteLine(string);(remaining members)Managed EXEstatic void Main(){Console.WriteLine(“Hello”);Console.WriteLine(“GoodBye”);}JITCompilerJITCompilerMSCorEE.dll…JITCompiler function{Look up the called method in the metadataGet the IL for it from metadataAllocate memoryCompile the IL into allocated memoryModify the method’s entry in the Type’s table so it points to allocated memoryJump to the native code contained inside the memory block.}Native CPU instr.
JITing18Consolestatic void WriteLine();static void WriteLine(string);(remaining members)Managed EXEstatic void Main(){Console.WriteLine(“Hello”);Console.WriteLine(“GoodBye”);}JITCompilerNativeMSCorEE.dll…JITCompiler function{Lookup the called method in the metadataGet the IL for it from metadataAllocate memoryCompile the IL into allocated memoryModify the method’s entry in the Type’s table so it points to allocated memoryJump to the native code contained inside the memory block.}Native CPU instr.
DEMO19
ResourcesCLR via C# 3, Jeffrey Richterwww.red-gate.comwww.stackoverflow.comMSDN20
Q&A21
22Please fill the evaluation formThank you very much!Sorin Oboroceanu, Vlad BalanRomSoft, www.rms.roIasi, May 4th 2010

More Related Content

PPTX
Performance in .net best practices
PDF
Apache Flink and More @ MesosCon Asia 2017
PDF
Flink Apachecon Presentation
PPTX
Fabian Hueske - Stream Analytics with SQL on Apache Flink
PDF
ElasticSearch Introduction
DOC
Typical Architecture Of Automation Frameworks
PPTX
Fabian Hueske_Till Rohrmann - Declarative stream processing with StreamSQL an...
PDF
How Anemic Objects Kill OOP
Performance in .net best practices
Apache Flink and More @ MesosCon Asia 2017
Flink Apachecon Presentation
Fabian Hueske - Stream Analytics with SQL on Apache Flink
ElasticSearch Introduction
Typical Architecture Of Automation Frameworks
Fabian Hueske_Till Rohrmann - Declarative stream processing with StreamSQL an...
How Anemic Objects Kill OOP

Similar to Performance In The .Net World (20)

PDF
Look Mommy, no GC! (BrightSource)
PPTX
ConFoo - Exploring .NET’s memory management – a trip down memory lane
PPT
Dot Net Framework
PPTX
Core .NET Framework 4.0 Enhancements
PPTX
Exploring .NET memory management - A trip down memory lane - Copenhagen .NET ...
PPTX
DotNetFest - Let’s refresh our memory! Memory management in .NET
PPTX
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
PPT
.Net Garbage Collector 101
PDF
Dot NET Interview Questions PDF By ScholarHat
PDF
.NET Fest 2018. Maarten Balliauw. Let’s refresh our memory! Memory management...
PPTX
Exploring .NET memory management - JetBrains webinar
PPTX
JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...
PPTX
Is2215 lecture5 lecturer_g_cand_classlibraries
PPTX
Debugging performance issues, memory issues and crashes in .net applications rev
PPTX
Exploring .NET memory management (iSense)
PPTX
Perf by design
PPTX
Performance in .NET - Best practices
PPTX
.NET Memory Primer
PDF
C# basics
Look Mommy, no GC! (BrightSource)
ConFoo - Exploring .NET’s memory management – a trip down memory lane
Dot Net Framework
Core .NET Framework 4.0 Enhancements
Exploring .NET memory management - A trip down memory lane - Copenhagen .NET ...
DotNetFest - Let’s refresh our memory! Memory management in .NET
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
.Net Garbage Collector 101
Dot NET Interview Questions PDF By ScholarHat
.NET Fest 2018. Maarten Balliauw. Let’s refresh our memory! Memory management...
Exploring .NET memory management - JetBrains webinar
JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...
Is2215 lecture5 lecturer_g_cand_classlibraries
Debugging performance issues, memory issues and crashes in .net applications rev
Exploring .NET memory management (iSense)
Perf by design
Performance in .NET - Best practices
.NET Memory Primer
C# basics
Ad

Performance In The .Net World

  • 1. Performance in the .NET world. A developer’s perspectiveSorin Oboroceanu, Vlad BalanRomSoft, www.rms.roIaşi, May 4th 2010
  • 4. Our Demo APPUses StackOverflow.com’s dataGroups users by locationDisplays user locations in a chartWill work in a client/server architectureHas performance issues 4
  • 5. CollectionsGroupping dataList<T>LINQ to ObjectsDictionary<T,V>5DEMO
  • 6. Client-Server communicationRetrieving all users on the clientGrouping dataList<T>LINQ to ObjectsDictionary<T,V>6DEMO
  • 7. Client-Server communicationGrouping data on the serverList<T>LINQ to ObjectsDictionary<T,V>Retrieving only location-related data on the client7DEMO
  • 9. Garbage CollectionWhy memory mattersGarbage CollectorCommon Memory IssuesDiagnosing Memory Problems 9
  • 10. Why memory mattersInefficient use of memory can impactPerformanceStabilityScalabilityOther ApplicationsHidden problems in code can causeMemory LeaksExcessive memory usageUnnecessary performance overhead10
  • 11. GC – Small Object Heap (SOH)11GCSmallObjectObjectA = new SmallObject(); SmallObjectObjectB = new SmallObject(); Global ObjectsSmall Object HeapNext Object PointerObjectENext Object PointerStackObjectDStatic ObjectsNext Object PointerObjectCNext Object PointerObjectBObjectBNext Object PointerObjectAObjectARoot ReferenceNext Object PointerChild Reference
  • 12. GC- Gen2LargeObjectObjectD= new LargeObject(); Global ObjectsFree space tableLarge Object Heap42500016777216ObjectD572740094208182272Free spaceStackObjectCObjectCObjectBFree spaceObjectBObjectAObjectA1212
  • 13. 13GC - Gen 0GC - Gen 1GC - Gen 2Small Object HeapGen 0Next Object PointerGlobal ObjectsObjectDObjectCNext Object PointerGen 1Static ObjectsStackObjectBGen 2ObjectARoot Reference
  • 14. GC – Minimizing Overheadpublic class Test: IDisposable{ ~Test() { Cleanup (false); } private void Cleanup(boolcodeDispose) { if (codeDispose) { // dispose managed resources } // clean up unmanaged resources } public void Dispose() { Cleanup (true); GC.SuppressFinalize(this); } }14
  • 15. GC – Common Memory IssuesExcessive RAM FootprintApp allocates objects too early or for too long using more memory than neededCan affect other apps on the systemExcessive Temporary Object allocationGarbage Collection runs more frequentlyExecuting threads freeze during Garbage CollectionMemory LeaksOverlooked root references keep objects alive (Collections, array, session state, delegates/events)Incorrect or absent Finalization can cause resources leaks15
  • 17. JITing17Consolestatic void WriteLine();static void WriteLine(string);(remaining members)Managed EXEstatic void Main(){Console.WriteLine(“Hello”);Console.WriteLine(“GoodBye”);}JITCompilerJITCompilerMSCorEE.dll…JITCompiler function{Look up the called method in the metadataGet the IL for it from metadataAllocate memoryCompile the IL into allocated memoryModify the method’s entry in the Type’s table so it points to allocated memoryJump to the native code contained inside the memory block.}Native CPU instr.
  • 18. JITing18Consolestatic void WriteLine();static void WriteLine(string);(remaining members)Managed EXEstatic void Main(){Console.WriteLine(“Hello”);Console.WriteLine(“GoodBye”);}JITCompilerNativeMSCorEE.dll…JITCompiler function{Lookup the called method in the metadataGet the IL for it from metadataAllocate memoryCompile the IL into allocated memoryModify the method’s entry in the Type’s table so it points to allocated memoryJump to the native code contained inside the memory block.}Native CPU instr.
  • 20. ResourcesCLR via C# 3, Jeffrey Richterwww.red-gate.comwww.stackoverflow.comMSDN20
  • 21. Q&A21
  • 22. 22Please fill the evaluation formThank you very much!Sorin Oboroceanu, Vlad BalanRomSoft, www.rms.roIasi, May 4th 2010