0
Performance in .NET:Best practicesSorin Oboroceanu, obs@rms.roVlad Balan, bav@rms.roRomSoft, www.rms.roIași, 8th of May 2010
Agenda Why performance matters Serialization Reading XML Garbage Collection JITing
Why performance matters Everyone loves performance Performance=money     Bing - 2 seconds slower – 4.3% drop in revenue...
Why performance matters Better apps – Satisfied customers
Our Demo APP Uses StackOverflow.com’s data Groups users by location Displays user locations in a chart Will work in a ...
Collections Groupping data   List<T>   LINQ to Objects   Dictionary<T,V>DEMO
Client-Server communication Retrieving all users on the client Grouping data   List<T>   LINQ to Objects   Dictionary...
Client-Server communication Grouping data on the server   List<T>   LINQ to Objects   Dictionary<T,V> Retrieving only...
Reading XML DataSet XmlReader LINQ to XML XmlDocumentDEMO
Garbage Collection Why memory matters Garbage Collector Object Finalization
Why memory matters Inefficient use of memory can impact     Performance     Stability     Scalability     Other Appli...
.NET Memory Management Small Object Heap (SOH) – Objects < 85K Large Object Heap (LOH) – Objects => 85K
Small Object Heap (SOH)                  GC          SmallObject ObjectB = new                      ObjectA               ...
GC - Gen 0                        2                        1 Generations          Small Object Heap               Gen 0   ...
Large Object Heap (LOH)              GC- Gen2          LargeObject ObjectD= new               LargeObject();              ...
GC     Finalization            FinObject ObjectE = new FinObject();                                                       ...
Finalization public class Test {    ~Test()    {            Cleanup ();     }    private void Cleanup()    {       // cle...
Disposable pattern public class Test : IDisposable{    ~Test()    {            Cleanup (false);     }    private void Cle...
DEMO
JITing                                               Console         Managed EXE                                          ...
JITing                                              Console         Managed EXE                                           ...
DEMO
Resources CLR via C# 3, Jeffrey Richter www.red-gate.com www.stackoverflow.com
Q&A
Please fill the evaluationformThank you very much!Sorin Oboroceanu, obs@rms.roVlad Balan, bav@rms.roRomSoft, www.rms.roIaș...
Upcoming SlideShare
Loading in...5
×

Performance in .NET - Best practices

257

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
257
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Performance in .NET - Best practices"

  1. 1. Performance in .NET:Best practicesSorin Oboroceanu, obs@rms.roVlad Balan, bav@rms.roRomSoft, www.rms.roIași, 8th of May 2010
  2. 2. Agenda Why performance matters Serialization Reading XML Garbage Collection JITing
  3. 3. Why performance matters Everyone loves performance Performance=money  Bing - 2 seconds slower – 4.3% drop in revenue  Google – 400ms slower – 0.6% drop in searches  Yahoo! – 400ms slower – 5-9% drop in full page traffic  Mozilla – 2.2 seconds faster – increased download conversion 15.4% Site speed is now taken into account in search rankings
  4. 4. Why performance matters Better apps – Satisfied customers
  5. 5. 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 
  6. 6. Collections Groupping data  List<T>  LINQ to Objects  Dictionary<T,V>DEMO
  7. 7. Client-Server communication Retrieving all users on the client Grouping data  List<T>  LINQ to Objects  Dictionary<T,V>DEMO
  8. 8. Client-Server communication Grouping data on the server  List<T>  LINQ to Objects  Dictionary<T,V> Retrieving only location-related data on the clientDEMO
  9. 9. Reading XML DataSet XmlReader LINQ to XML XmlDocumentDEMO
  10. 10. Garbage Collection Why memory matters Garbage Collector Object Finalization
  11. 11. 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
  12. 12. .NET Memory Management Small Object Heap (SOH) – Objects < 85K Large Object Heap (LOH) – Objects => 85K
  13. 13. Small Object Heap (SOH) GC SmallObject ObjectB = new ObjectA SmallObject();GlobalObjects Small Object Heap Next Object Pointer ObjectE Next Object PointerStack ObjectD Next Object Pointer Static Objects ObjectC Next Object PointerObjectB ObjectB Next Object PointerObjectA Root Reference ObjectA Next Object Pointer Child Reference
  14. 14. GC - Gen 0 2 1 Generations Small Object Heap Gen 0 Next Object PointerGlobal ObjectDObjects ObjectC Next Object Pointer Gen 1 StaticStack Objects ObjectB Gen 2 Root Reference ObjectA
  15. 15. Large Object Heap (LOH) GC- Gen2 LargeObject ObjectD= new LargeObject(); Free space tableGlobalObjects Large Object Heap From To 5727400 425000 16777216 ObjectD 94208 182272Stack Free spaceObjectC ObjectC Free space ObjectBObjectB ObjectAObjectA
  16. 16. GC Finalization FinObject ObjectE = new FinObject(); Finalization Queue Small Object Heap Gen 0GlobalObjects ObjectE Finalize() ObjectE fReachable ObjectD Queue Finalizer Stack ObjectC thread Gen 1 ObjectB ObjectB ObjectA ObjectA
  17. 17. Finalization public class Test { ~Test() { Cleanup (); } private void Cleanup() { // clean up unmanaged resources } }
  18. 18. Disposable pattern public class Test : IDisposable{ ~Test() { Cleanup (false); } private void Cleanup(bool codeDispose) { if (codeDispose) { // dispose managed resources } // clean up unmanaged resources } public void Dispose() { Cleanup (true); GC.SuppressFinalize(this); } }
  19. 19. DEMO
  20. 20. JITing Console Managed EXE static void WriteLine(); static void Main(){ Console.WriteLine(“Hello”); JITCompiler Console.WriteLine(“GoodBye”); } static void WriteLine(string); JITCompiler MSCorEE.dll (remaining members)JITCompiler function{ …1. Look up the called method in the metadata2. Get the IL for it from metadata3. Allocate memory4. Compile the IL into allocated memory5. Modify the method’s entry in the Type’s table so it points to allocated memory Native6. Jump to the native code contained inside CPU the memory block. instr.}
  21. 21. JITing Console Managed EXE static void WriteLine(); static void Main(){ Console.WriteLine(“Hello”); JITCompiler Console.WriteLine(“GoodBye”); } static void WriteLine(string); Native MSCorEE.dll (remaining members)JITCompiler function{ …1. Lookup the called method in the metadata2. Get the IL for it from metadata3. Allocate memory4. Compile the IL into allocated memory5. Modify the method’s entry in the Type’s table so it points to allocated memory Native6. Jump to the native code contained inside CPU the memory block.} instr.
  22. 22. DEMO
  23. 23. Resources CLR via C# 3, Jeffrey Richter www.red-gate.com www.stackoverflow.com
  24. 24. Q&A
  25. 25. Please fill the evaluationformThank you very much!Sorin Oboroceanu, obs@rms.roVlad Balan, bav@rms.roRomSoft, www.rms.roIași, 8th of May 2010
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×