1 / 10

Five patterns for Green Programming

Five patterns for Green Programming. JP Gouigoux, MVP. Goals. Show most common smells Explain why they are a pain Provide a solution How to detect them. Correct use of loops. THE typical smell Principle #1 : reduce number of iterations Principle # 2 : reduce content

Download Presentation

Five patterns for Green Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Five patterns for Green Programming JP Gouigoux, MVP

  2. Goals • Show mostcommonsmells • Explainwhythey are a pain • Provide a solution • How to detectthem

  3. Correct use of loops • THE typicalsmell • Principle #1 : reducenumber of iterations • Principle#2 : reduce content • Principle#3 : use cache effects • Pattern seen in a profiler :

  4. Correct use of exceptions • 1 exception ≈ 1000 boolean tests • Only use in exceptional cases, as the nameindicates

  5. Correct use of exceptions • Any good profiler shows them • As much as possible, stay in situations where exceptions cannothappen

  6. Fair use of memory • Master variables life cycle • Latecreation / early release • GC generations ratio : 1 / 10 / 1000 • Never call GC.Collect() • Understand memory leaks • Understand fragmentation

  7. Choosing the right API • No secret : RTFM • Typical case : string concatenation • .NET criteria: 5 operations

  8. Choosing the right API • Hint: check for unbalanced distributions

  9. Stream instead of load • StreamReaderor StreamWriterinstead of File.Readou File.Append • XmlTextReaderor XmlTextWriterinstead of XmlDocument • Everythingisgreat in Linq • Stream chaining • Lazyloading • Parallelism

  10. A few more recommendations • Use a profiler • Optimize hot paths first • Set a clear objective • Know yourplatform in depth • Do not confuse performance(speed) with performance(efficiency)

More Related