SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Performance in the .NET world. A developer’s perspective Sorin Oboroceanu, Vlad Balan RomSoft, www.rms.ro Iaşi, May 4th 2010
Agenda String vs. StringBuilder Serialization Reading XML Garbage Collection JITing 2
String vs. StringBuilder 3 DEMO
Our Demo APP Uses StackOverflow.com’s data Groups users by location Displays user locations in a chart Will work in a client/server architecture Has performance issues  4
Collections Groupping data List<T> LINQ to Objects Dictionary<T,V> 5 DEMO
Client-Server communication Retrieving all users on the client Grouping data List<T> LINQ to Objects Dictionary<T,V> 6 DEMO
Client-Server communication Grouping data on the server List<T> LINQ to Objects Dictionary<T,V> Retrieving only location-related data on the client 7 DEMO
Reading XML DataSet XmlReader LINQ to XML XmlDocument 8 DEMO
Garbage Collection Why memory matters Garbage Collector Common Memory Issues Diagnosing Memory Problems  9
Why memory matters Inefficient use of memory can impact Performance Stability Scalability Other Applications Hidden problems in code can cause Memory Leaks Excessive memory usage Unnecessary performance overhead 10
GC – Small Object Heap (SOH) 11 GC SmallObjectObjectA = new SmallObject();  SmallObjectObjectB = new SmallObject();  Global Objects Small Object  Heap Next Object Pointer ObjectE Next Object Pointer Stack ObjectD Static Objects Next Object Pointer ObjectC Next Object Pointer ObjectB ObjectB Next Object Pointer ObjectA ObjectA Root Reference Next Object Pointer Child Reference
GC- Gen2 LargeObjectObjectD= new LargeObject();  Global Objects Free space table Large Object  Heap 425000 16777216 ObjectD 5727400 94208 182272 Free space Stack ObjectC ObjectC ObjectB Free space ObjectB ObjectA ObjectA 12 12
13 GC - Gen 0 GC - Gen 1 GC - Gen 2 Small Object  Heap Gen 0 Next Object Pointer Global Objects ObjectD ObjectC Next Object Pointer Gen 1 Static Objects Stack ObjectB Gen 2 ObjectA Root Reference
GC – Minimizing Overhead public 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 Issues Excessive RAM Footprint App allocates objects too early or for too long using more memory than needed Can affect other apps on the system Excessive Temporary Object allocation Garbage Collection runs more frequently Executing threads freeze during Garbage Collection Memory Leaks Overlooked root references keep objects alive (Collections, array, session state, delegates/events) Incorrect or absent Finalization can cause resources leaks 15
DEMO 16
JITing 17 Console static void WriteLine(); static void WriteLine(string); (remaining members) Managed EXE static void Main(){ Console.WriteLine(“Hello”); Console.WriteLine(“GoodBye”); } JITCompiler JITCompiler MSCorEE.dll … JITCompiler function{ Look up the called method in the metadata Get the IL for it from metadata Allocate memory Compile the IL into allocated memory Modify the method’s entry in the Type’s table so it points to allocated memory Jump to the native code contained inside the memory block. } Native CPU instr.
JITing 18 Console static void WriteLine(); static void WriteLine(string); (remaining members) Managed EXE static void Main(){ Console.WriteLine(“Hello”); Console.WriteLine(“GoodBye”); } JITCompiler Native MSCorEE.dll … JITCompiler function{ Lookup the called method in the metadata Get the IL for it from metadata Allocate memory Compile the IL into allocated memory Modify the method’s entry in the Type’s table so it points to allocated memory Jump to the native code contained inside the memory block.} Native CPU instr.
DEMO 19
Resources CLR via C# 3, Jeffrey Richter www.red-gate.com www.stackoverflow.com MSDN 20
Q&A 21
22 Please fill the evaluation form Thank you very much! Sorin Oboroceanu, Vlad Balan RomSoft, www.rms.ro Iasi, May 4th 2010

Weitere ähnliche Inhalte

Ähnlich wie Performance In The .Net World

Accelerated data access
Accelerated data accessAccelerated data access
Accelerated data accessgordonyorke
 
Java one 2010
Java one 2010Java one 2010
Java one 2010scdn
 
Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4Darwin Biler
 
Stored-Procedures-Presentation
Stored-Procedures-PresentationStored-Procedures-Presentation
Stored-Procedures-PresentationChuck Walker
 
Nagios Conference 2013 - Eric Stanley and Andy Brist - API and Nagios
Nagios Conference 2013 - Eric Stanley and Andy Brist - API and NagiosNagios Conference 2013 - Eric Stanley and Andy Brist - API and Nagios
Nagios Conference 2013 - Eric Stanley and Andy Brist - API and NagiosNagios
 
GemFire In Memory Data Grid
GemFire In Memory Data GridGemFire In Memory Data Grid
GemFire In Memory Data GridDmitry Buzdin
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)Montreal JUG
 
Active Data: Managing Data-Life Cycle on Heterogeneous Systems and Infrastruc...
Active Data: Managing Data-Life Cycle on Heterogeneous Systems and Infrastruc...Active Data: Managing Data-Life Cycle on Heterogeneous Systems and Infrastruc...
Active Data: Managing Data-Life Cycle on Heterogeneous Systems and Infrastruc...Gilles Fedak
 
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeBoost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeMarco Gralike
 
Software Engineering - RS4
Software Engineering - RS4Software Engineering - RS4
Software Engineering - RS4AtakanAral
 
Zend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingZend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingTricode (part of Dept)
 
The Best Way to Become an Android Developer Expert with Android Jetpack
The Best Way to Become an Android Developer Expert  with Android JetpackThe Best Way to Become an Android Developer Expert  with Android Jetpack
The Best Way to Become an Android Developer Expert with Android JetpackAhmad Arif Faizin
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptjasonsich
 
Backbone.js and friends
Backbone.js and friendsBackbone.js and friends
Backbone.js and friendsGood Robot
 
Easing offline web application development with GWT
Easing offline web application development with GWTEasing offline web application development with GWT
Easing offline web application development with GWTArnaud Tournier
 

Ähnlich wie Performance In The .Net World (20)

Accelerated data access
Accelerated data accessAccelerated data access
Accelerated data access
 
Java one 2010
Java one 2010Java one 2010
Java one 2010
 
Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4
 
ORM JPA
ORM JPAORM JPA
ORM JPA
 
Stored-Procedures-Presentation
Stored-Procedures-PresentationStored-Procedures-Presentation
Stored-Procedures-Presentation
 
Nagios Conference 2013 - Eric Stanley and Andy Brist - API and Nagios
Nagios Conference 2013 - Eric Stanley and Andy Brist - API and NagiosNagios Conference 2013 - Eric Stanley and Andy Brist - API and Nagios
Nagios Conference 2013 - Eric Stanley and Andy Brist - API and Nagios
 
GemFire In-Memory Data Grid
GemFire In-Memory Data GridGemFire In-Memory Data Grid
GemFire In-Memory Data Grid
 
GemFire In Memory Data Grid
GemFire In Memory Data GridGemFire In Memory Data Grid
GemFire In Memory Data Grid
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)
 
Active Data: Managing Data-Life Cycle on Heterogeneous Systems and Infrastruc...
Active Data: Managing Data-Life Cycle on Heterogeneous Systems and Infrastruc...Active Data: Managing Data-Life Cycle on Heterogeneous Systems and Infrastruc...
Active Data: Managing Data-Life Cycle on Heterogeneous Systems and Infrastruc...
 
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeBoost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
 
Software Engineering - RS4
Software Engineering - RS4Software Engineering - RS4
Software Engineering - RS4
 
Zend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingZend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching logging
 
The Best Way to Become an Android Developer Expert with Android Jetpack
The Best Way to Become an Android Developer Expert  with Android JetpackThe Best Way to Become an Android Developer Expert  with Android Jetpack
The Best Way to Become an Android Developer Expert with Android Jetpack
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScript
 
Flink internals web
Flink internals web Flink internals web
Flink internals web
 
Backbone.js and friends
Backbone.js and friendsBackbone.js and friends
Backbone.js and friends
 
Basic Hibernate Final
Basic Hibernate FinalBasic Hibernate Final
Basic Hibernate Final
 
Scope Stack Allocation
Scope Stack AllocationScope Stack Allocation
Scope Stack Allocation
 
Easing offline web application development with GWT
Easing offline web application development with GWTEasing offline web application development with GWT
Easing offline web application development with GWT
 

Performance In The .Net World

  • 1. Performance in the .NET world. A developer’s perspective Sorin Oboroceanu, Vlad Balan RomSoft, www.rms.ro Iaşi, May 4th 2010
  • 2. Agenda String vs. StringBuilder Serialization Reading XML Garbage Collection JITing 2
  • 4. Our Demo APP Uses StackOverflow.com’s data Groups users by location Displays user locations in a chart Will work in a client/server architecture Has performance issues  4
  • 5. Collections Groupping data List<T> LINQ to Objects Dictionary<T,V> 5 DEMO
  • 6. Client-Server communication Retrieving all users on the client Grouping data List<T> LINQ to Objects Dictionary<T,V> 6 DEMO
  • 7. Client-Server communication Grouping data on the server List<T> LINQ to Objects Dictionary<T,V> Retrieving only location-related data on the client 7 DEMO
  • 8. Reading XML DataSet XmlReader LINQ to XML XmlDocument 8 DEMO
  • 9. Garbage Collection Why memory matters Garbage Collector Common Memory Issues Diagnosing Memory Problems 9
  • 10. Why memory matters Inefficient use of memory can impact Performance Stability Scalability Other Applications Hidden problems in code can cause Memory Leaks Excessive memory usage Unnecessary performance overhead 10
  • 11. GC – Small Object Heap (SOH) 11 GC SmallObjectObjectA = new SmallObject(); SmallObjectObjectB = new SmallObject(); Global Objects Small Object Heap Next Object Pointer ObjectE Next Object Pointer Stack ObjectD Static Objects Next Object Pointer ObjectC Next Object Pointer ObjectB ObjectB Next Object Pointer ObjectA ObjectA Root Reference Next Object Pointer Child Reference
  • 12. GC- Gen2 LargeObjectObjectD= new LargeObject(); Global Objects Free space table Large Object Heap 425000 16777216 ObjectD 5727400 94208 182272 Free space Stack ObjectC ObjectC ObjectB Free space ObjectB ObjectA ObjectA 12 12
  • 13. 13 GC - Gen 0 GC - Gen 1 GC - Gen 2 Small Object Heap Gen 0 Next Object Pointer Global Objects ObjectD ObjectC Next Object Pointer Gen 1 Static Objects Stack ObjectB Gen 2 ObjectA Root Reference
  • 14. GC – Minimizing Overhead public 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 Issues Excessive RAM Footprint App allocates objects too early or for too long using more memory than needed Can affect other apps on the system Excessive Temporary Object allocation Garbage Collection runs more frequently Executing threads freeze during Garbage Collection Memory Leaks Overlooked root references keep objects alive (Collections, array, session state, delegates/events) Incorrect or absent Finalization can cause resources leaks 15
  • 17. JITing 17 Console static void WriteLine(); static void WriteLine(string); (remaining members) Managed EXE static void Main(){ Console.WriteLine(“Hello”); Console.WriteLine(“GoodBye”); } JITCompiler JITCompiler MSCorEE.dll … JITCompiler function{ Look up the called method in the metadata Get the IL for it from metadata Allocate memory Compile the IL into allocated memory Modify the method’s entry in the Type’s table so it points to allocated memory Jump to the native code contained inside the memory block. } Native CPU instr.
  • 18. JITing 18 Console static void WriteLine(); static void WriteLine(string); (remaining members) Managed EXE static void Main(){ Console.WriteLine(“Hello”); Console.WriteLine(“GoodBye”); } JITCompiler Native MSCorEE.dll … JITCompiler function{ Lookup the called method in the metadata Get the IL for it from metadata Allocate memory Compile the IL into allocated memory Modify the method’s entry in the Type’s table so it points to allocated memory Jump to the native code contained inside the memory block.} Native CPU instr.
  • 20. Resources CLR via C# 3, Jeffrey Richter www.red-gate.com www.stackoverflow.com MSDN 20
  • 22. 22 Please fill the evaluation form Thank you very much! Sorin Oboroceanu, Vlad Balan RomSoft, www.rms.ro Iasi, May 4th 2010