SlideShare une entreprise Scribd logo
1  sur  25
Performance in .NET:
Best practices
Sorin Oboroceanu, obs@rms.ro
Vlad Balan, bav@rms.ro
RomSoft, www.rms.ro
Iaș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 client




DEMO
Reading XML
 DataSet
 XmlReader
 LINQ to XML
 XmlDocument




DEMO
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();
Global
Objects   Small Object Heap
                                 Next Object Pointer

                ObjectE
                                 Next Object Pointer
Stack
                ObjectD
                                 Next Object Pointer      Static
                                                         Objects
                ObjectC
                                 Next Object Pointer
ObjectB         ObjectB
                                 Next Object Pointer
ObjectA                                                Root Reference
                ObjectA
                                 Next Object Pointer   Child Reference
GC - Gen 0
                        2
                        1
 Generations
          Small Object Heap
               Gen 0          Next Object Pointer
Global         ObjectD
Objects
               ObjectC
                              Next Object Pointer

               Gen 1
                                                         Static
Stack                                                   Objects
               ObjectB

               Gen 2



                                                    Root Reference
               ObjectA
Large Object Heap (LOH)
              GC- Gen2
          LargeObject ObjectD= new
               LargeObject();
                                          Free space table
Global
Objects   Large Object Heap             From            To
                                     5727400
                                     425000       16777216
                ObjectD
                                     94208       182272


Stack          Free space



ObjectC          ObjectC

               Free space
                ObjectB
ObjectB
                 ObjectA
ObjectA
GC

     Finalization
            FinObject ObjectE = new FinObject();
                                                                Finalization
                                                                   Queue

                Small Object Heap

                        Gen 0
Global
Objects                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 metadata
2. Get the IL for it from metadata
3. Allocate memory
4. Compile the IL into allocated memory
5. Modify the method’s entry in the Type’s
   table so it points to allocated memory               Native
6. 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 metadata
2. Get the IL for it from metadata
3. Allocate memory
4. Compile the IL into allocated memory
5. Modify the method’s entry in the Type’s
   table so it points to allocated memory              Native
6. 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 evaluation
form

Thank you very much!
Sorin Oboroceanu, obs@rms.ro
Vlad Balan, bav@rms.ro
RomSoft, www.rms.ro
Iași, 8th of May 2010

Contenu connexe

Tendances

Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
Systematic Generation Data and Types in C++
Systematic Generation Data and Types in C++Systematic Generation Data and Types in C++
Systematic Generation Data and Types in C++Sumant Tambe
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokusHamletDRC
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?Squareboat
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersBartosz Kosarzycki
 
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Abu Saleh
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyIván López Martín
 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalkkim.mens
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)HamletDRC
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
PDC Video on C# 4.0 Futures
PDC Video on C# 4.0 FuturesPDC Video on C# 4.0 Futures
PDC Video on C# 4.0 Futuresnithinmohantk
 
Garbage collector in python
Garbage collector in pythonGarbage collector in python
Garbage collector in pythonIbrahim Kasim
 

Tendances (18)

Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Android JNI
Android JNIAndroid JNI
Android JNI
 
NS2 Shadow Object Construction
NS2 Shadow Object ConstructionNS2 Shadow Object Construction
NS2 Shadow Object Construction
 
Systematic Generation Data and Types in C++
Systematic Generation Data and Types in C++Systematic Generation Data and Types in C++
Systematic Generation Data and Types in C++
 
Qtp Summary
Qtp SummaryQtp Summary
Qtp Summary
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Invoke Dynamic
Invoke DynamicInvoke Dynamic
Invoke Dynamic
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalk
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Developing android apps with java 8
Developing android apps with java 8Developing android apps with java 8
Developing android apps with java 8
 
PDC Video on C# 4.0 Futures
PDC Video on C# 4.0 FuturesPDC Video on C# 4.0 Futures
PDC Video on C# 4.0 Futures
 
Garbage collector in python
Garbage collector in pythonGarbage collector in python
Garbage collector in python
 

Similaire à Best practices for improving .NET performance

Synthesizing API Usage Examples
Synthesizing API Usage Examples Synthesizing API Usage Examples
Synthesizing API Usage Examples Ray Buse
 
Performance in .net best practices
Performance in .net best practicesPerformance in .net best practices
Performance in .net best practicesCodecamp Romania
 
Virtual Separation of Concerns
Virtual Separation of ConcernsVirtual Separation of Concerns
Virtual Separation of Concernschk49
 
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24  tricky stuff in java grammar and javacJug trojmiasto 2014.04.24  tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javacAnna Brzezińska
 
Ejb 2.0
Ejb 2.0Ejb 2.0
Ejb 2.0sukace
 
The Possibilities and Pitfalls of Writing Your Own State Stores with Daan Gertis
The Possibilities and Pitfalls of Writing Your Own State Stores with Daan GertisThe Possibilities and Pitfalls of Writing Your Own State Stores with Daan Gertis
The Possibilities and Pitfalls of Writing Your Own State Stores with Daan GertisHostedbyConfluent
 
Strategies to improve embedded Linux application performance beyond ordinary ...
Strategies to improve embedded Linux application performance beyond ordinary ...Strategies to improve embedded Linux application performance beyond ordinary ...
Strategies to improve embedded Linux application performance beyond ordinary ...André Oriani
 
Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5phanleson
 
From Java to Kotlin - The first month in practice v2
From Java to Kotlin - The first month in practice v2From Java to Kotlin - The first month in practice v2
From Java to Kotlin - The first month in practice v2StefanTomm
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin XPeppers
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...go_oh
 

Similaire à Best practices for improving .NET performance (20)

Android ndk
Android ndkAndroid ndk
Android ndk
 
Android and cpp
Android and cppAndroid and cpp
Android and cpp
 
Synthesizing API Usage Examples
Synthesizing API Usage Examples Synthesizing API Usage Examples
Synthesizing API Usage Examples
 
Performance in .net best practices
Performance in .net best practicesPerformance in .net best practices
Performance in .net best practices
 
Virtual Separation of Concerns
Virtual Separation of ConcernsVirtual Separation of Concerns
Virtual Separation of Concerns
 
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24  tricky stuff in java grammar and javacJug trojmiasto 2014.04.24  tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
 
EJB Clients
EJB ClientsEJB Clients
EJB Clients
 
Ejb examples
Ejb examplesEjb examples
Ejb examples
 
Ejb 2.0
Ejb 2.0Ejb 2.0
Ejb 2.0
 
The Possibilities and Pitfalls of Writing Your Own State Stores with Daan Gertis
The Possibilities and Pitfalls of Writing Your Own State Stores with Daan GertisThe Possibilities and Pitfalls of Writing Your Own State Stores with Daan Gertis
The Possibilities and Pitfalls of Writing Your Own State Stores with Daan Gertis
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Strategies to improve embedded Linux application performance beyond ordinary ...
Strategies to improve embedded Linux application performance beyond ordinary ...Strategies to improve embedded Linux application performance beyond ordinary ...
Strategies to improve embedded Linux application performance beyond ordinary ...
 
Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5
 
From Java to Kotlin - The first month in practice v2
From Java to Kotlin - The first month in practice v2From Java to Kotlin - The first month in practice v2
From Java to Kotlin - The first month in practice v2
 
C# for beginners
C# for beginnersC# for beginners
C# for beginners
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
 
ICPC08b.ppt
ICPC08b.pptICPC08b.ppt
ICPC08b.ppt
 
ICPC08b.ppt
ICPC08b.pptICPC08b.ppt
ICPC08b.ppt
 
Basics of building a blackfin application
Basics of building a blackfin applicationBasics of building a blackfin application
Basics of building a blackfin application
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 

Dernier

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Dernier (20)

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

Best practices for improving .NET performance

  • 1. Performance in .NET: Best practices Sorin Oboroceanu, obs@rms.ro Vlad Balan, bav@rms.ro RomSoft, www.rms.ro Iași, 8th of May 2010
  • 2. Agenda  Why performance matters  Serialization  Reading XML  Garbage Collection  JITing
  • 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. Why performance matters  Better apps – Satisfied customers
  • 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. Collections  Groupping data  List<T>  LINQ to Objects  Dictionary<T,V> DEMO
  • 7. Client-Server communication  Retrieving all users on the client  Grouping data  List<T>  LINQ to Objects  Dictionary<T,V> DEMO
  • 8. Client-Server communication  Grouping data on the server  List<T>  LINQ to Objects  Dictionary<T,V>  Retrieving only location-related data on the client DEMO
  • 9. Reading XML  DataSet  XmlReader  LINQ to XML  XmlDocument DEMO
  • 10. Garbage Collection  Why memory matters  Garbage Collector  Object Finalization
  • 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. .NET Memory Management  Small Object Heap (SOH) – Objects < 85K  Large Object Heap (LOH) – Objects => 85K
  • 13. Small Object Heap (SOH) GC SmallObject ObjectB = new ObjectA SmallObject(); Global Objects Small Object Heap Next Object Pointer ObjectE Next Object Pointer Stack ObjectD Next Object Pointer Static Objects ObjectC Next Object Pointer ObjectB ObjectB Next Object Pointer ObjectA Root Reference ObjectA Next Object Pointer Child Reference
  • 14. GC - Gen 0 2 1 Generations Small Object Heap Gen 0 Next Object Pointer Global ObjectD Objects ObjectC Next Object Pointer Gen 1 Static Stack Objects ObjectB Gen 2 Root Reference ObjectA
  • 15. Large Object Heap (LOH) GC- Gen2 LargeObject ObjectD= new LargeObject(); Free space table Global Objects Large Object Heap From To 5727400 425000 16777216 ObjectD 94208 182272 Stack Free space ObjectC ObjectC Free space ObjectB ObjectB ObjectA ObjectA
  • 16. GC Finalization FinObject ObjectE = new FinObject(); Finalization Queue Small Object Heap Gen 0 Global Objects ObjectE Finalize() ObjectE fReachable ObjectD Queue Finalizer Stack ObjectC thread Gen 1 ObjectB ObjectB ObjectA ObjectA
  • 17. Finalization  public class Test { ~Test() { Cleanup (); } private void Cleanup() { // clean up unmanaged resources } }
  • 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. DEMO
  • 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 metadata 2. Get the IL for it from metadata 3. Allocate memory 4. Compile the IL into allocated memory 5. Modify the method’s entry in the Type’s table so it points to allocated memory Native 6. Jump to the native code contained inside CPU the memory block. instr. }
  • 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 metadata 2. Get the IL for it from metadata 3. Allocate memory 4. Compile the IL into allocated memory 5. Modify the method’s entry in the Type’s table so it points to allocated memory Native 6. Jump to the native code contained inside CPU the memory block.} instr.
  • 22. DEMO
  • 23. Resources  CLR via C# 3, Jeffrey Richter  www.red-gate.com  www.stackoverflow.com
  • 24. Q&A
  • 25. Please fill the evaluation form Thank you very much! Sorin Oboroceanu, obs@rms.ro Vlad Balan, bav@rms.ro RomSoft, www.rms.ro Iași, 8th of May 2010