Performance in .NET - Best practices
Upcoming SlideShare
Loading in...5
×
 

Performance in .NET - Best practices

on

  • 298 views

 

Statistics

Views

Total Views
298
Views on SlideShare
290
Embed Views
8

Actions

Likes
0
Downloads
4
Comments
0

2 Embeds 8

http://www.linkedin.com 7
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Performance in .NET - Best practices Performance in .NET - Best practices Presentation Transcript

    • 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  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
    • 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 client/server architecture Has performance issues 
    • 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<T,V>DEMO
    • Client-Server communication Grouping data on the server  List<T>  LINQ to Objects  Dictionary<T,V> Retrieving only location-related data on the clientDEMO
    • 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 Applications Hidden problems in code can cause  Memory Leaks  Excessive memory usage  Unnecessary performance overhead
    • .NET Memory Management Small Object Heap (SOH) – Objects < 85K Large Object Heap (LOH) – Objects => 85K
    • 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
    • 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
    • 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
    • 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
    • Finalization public class Test { ~Test() { Cleanup (); } private void Cleanup() { // clean up unmanaged resources } }
    • 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); } }
    • DEMO
    • 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.}
    • 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.
    • 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și, 8th of May 2010