You are previewing Writing High-Performance .NET Code.
O'Reilly logo
Writing High-Performance .NET Code

Book Description

Get the best performance out of .NET by learning how the CLR works and what you can do to optimize your code, measure your performance, and diagnose problems quickly with free tools.

Table of Contents

  1. Table of Contents
  2. About the Author
  3. About the Technical Editor
  4. Acknowledgements
  5. Introduction
    1. Purpose of this Book
    2. Why Should You Choose Managed Code?
    3. Is Managed Code Slower Than Native Code?
    4. Am I Giving Up Control?
    5. Work With the CLR, Not Against It
    6. Layers of Optimization
    7. Sample Source Code
    8. Why Gears?
  6. Chapter 1 Performance Measurement and Tools
    1. Choosing What to Measure
    2. Average vs. Percentiles
    3. Measurement Tools
    4. Summary
  7. Chapter 2 Garbage Collection
    1. Basic Operation
    2. Configuration Options
    3. Reduce Allocation Rate
    4. The Most Important Rule
    5. Reduce Object Lifetime
    6. Reduce Depth of Trees
    7. Reduce References between Objects
    8. Avoid Pinning
    9. Avoid Finalizers
    10. Avoid Large Object Allocations
    11. Avoid Copying Buffers
    12. Pool Long-Lived and Large Objects
    13. Reduce Large Object Heap Fragmentation
    14. Force Full GCs in Some Circumstances
    15. Compact the Large Object Heap On-Demand
    16. Get Notified of Collections Before They Happen
    17. Use Weak References for Caching
    18. Measuring and Investigating GC Performance
    19. Summary
  8. Chapter 3 JIT Compilation
    1. Benefits of JIT Compilation
    2. Costs of JIT Compilation
    3. JIT Compiler Optimizations
    4. Reducing JIT and Startup Time
    5. Optimizing JITting with Profiling
    6. When to Use NGEN
    7. When JIT Can’t Compete
    8. Measurement
    9. Summary
  9. Chapter 4 Asynchronous Programming
    1. Use Tasks
    2. Parallel Loops
    3. Avoid Blocking
    4. Use Tasks for Non-Blocking I/O
    5. Async and Await
    6. A Note on Program Structure
    7. Use Timers Correctly
    8. Ensure Good Startup Thread Pool Size
    9. Do Not Abort Threads
    10. Do Not Change Thread Priorities
    11. Thread Synchronization and Locks
    12. Measurement
    13. Summary
  10. Chapter 5 General Coding and Class Design
    1. Class vs. Struct
    2. Override Equals and GetHashCode for Structs
    3. Virtual Methods and Sealed Classes
    4. Interface Dispatch
    5. Avoid Boxing
    6. for vs. foreach
    7. Casting
    8. P/Invoke
    9. Delegates
    10. Exceptions
    11. Dynamic
    12. Code Generation
    13. Preprocessing
    14. Measurement
    15. Summary
  11. Chapter 6 Using the .NET Framework
    1. Understand Every API you call
    2. Multiple APIs for the Same Thing
    3. Collections
    4. Strings
    5. Avoid APIs that Throw Exceptions under Normal Circumstances
    6. Avoid APIs That Allocate From the Large Object Heap
    7. Use Lazy Initialization
    8. The Surprisingly High Cost of Enum
    9. Tracking Time
    10. Regular Expressions
    11. LINQ
    12. Reading Files
    13. Optimize HTTP Settings and Network Communication
    14. Reflection
    15. Measurement
    16. Summary
  12. Chapter 7 Performance Counters
    1. Consuming Existing Counters
    2. Creating a Custom Counter
    3. Summary
  13. Chapter 8 ETW Events
    1. Defining Events
    2. Consume Custom Events in PerfView
    3. Create a Custom ETW Event Listener
    4. Get Detailed EventSource Data
    5. Custom PerfView Analysis Extension
    6. Summary
  14. Chapter 9 Windows Phone
    1. Tools
    2. Garbage Collection and Memory
    3. JIT
    4. Asynchronous Programming and Memory Models
    5. Other Considerations
    6. Summary
  15. Chapter 10 Code Safety
    1. Understand the Underlying OS, APIs, and Hardware
    2. Restrict API Usage in Certain Areas of Your Code
    3. Centralize and Abstract Performance-Sensitive and Difficult Code
    4. Isolate Unmanaged or Unsafe Code
    5. Prefer Code Clarity to Performance Until Proven Otherwise
    6. Summary
  16. Chapter 11 Building a Performance-Minded Team
    1. Understand the Areas of Critical Performance
    2. Effective Testing
    3. Performance Infrastructure and Automation
    4. Believe Only Numbers
    5. Effective Code Reviews
    6. Education
    7. Summary
  17. Appendix A—Kick-Start Your Application’s Performance
    1. Define Metrics
    2. Analyze CPU Usage
    3. Analyze Memory Usage
    4. Analyze JIT
    5. Analyze Asynchronous Performance
  18. Appendix B—Big O Notation
    1. Common Algorithms and Their Complexity
  19. Appendix C—Bibliography
    1. Useful Books
    2. People and Blogs
  20. Contact Information