Performance in .net best practices
- 1. Performance in .NET: Best practicesSorin Oboroceanu, obs@rms.roVlad Balan, bav@rms.roRomSoft, www.rms.roIași, 8th of May 2010
- 3. Why performance mattersEveryone loves performancePerformance=moneyBing - 2 seconds slower – 4.3% drop in revenueGoogle – 400ms slower – 0.6% drop in searchesYahoo! – 400ms slower – 5-9% drop in full page trafficMozilla – 2.2 seconds faster – increased download conversion 15.4%Site speed is now taken into account in search rankings
- 5. Our Demo APPUses StackOverflow.com’s dataGroups users by locationDisplays user locations in a chartWill work in a client/server architectureHas performance issues
- 11. Why memory mattersInefficient use of memory can impactPerformanceStabilityScalabilityOther ApplicationsHidden problems in code can causeMemory LeaksExcessive memory usageUnnecessary performance overhead
- 13. Small Object Heap (SOH)GCSmallObjectObjectA = new SmallObject(); SmallObjectObjectB = new SmallObject(); Global ObjectsSmall Object HeapNext Object PointerObjectENext Object PointerStackObjectDStatic ObjectsNext Object PointerObjectCNext Object PointerObjectBObjectBNext Object PointerObjectARoot ReferenceObjectANext Object PointerChild Reference
- 14. GenerationsGC - Gen 0GC - Gen 1GC - Gen 2Small Object HeapGen 0Next Object PointerGlobal ObjectsObjectDObjectCNext Object PointerGen 1Static ObjectsStackObjectBGen 2Root ReferenceObjectA
- 15. Large Object Heap (LOH)GC- Gen2LargeObjectObjectD= new LargeObject(); Global ObjectsFree space tableLarge Object Heap572740042500016777216ObjectD94208182272Free spaceStackObjectCObjectCObjectBFree spaceObjectBObjectAObjectA
- 18. Disposable patternpublic 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); } }
- 20. JITingConsolestatic 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.
- 21. JITingConsolestatic 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.
- 25. Please fill the evaluation formThank you very much!Sorin Oboroceanu, obs@rms.roVlad Balan, bav@rms.roRomSoft, www.rms.roIași, 8th of May 2010