AspNetCore Performance Checklist

best-practices documentation
  • Use Profiling tools

    • VS Profiler

    • Jetbrains dotTrace

    • PerfView

  • Implement Caching

    • In-memory caching or distributed caching using Memory Cache or Redis.

  • Database Optimization

    • Use proper indexing and stored procedures.

    • Connection pooling to reuse database connections

  • Asynchronous Programming

    • For I/O bound scenarios, use async and await always.

  • Use EF Core wisely

    • Use eager loading, projections, and optimizations like compiled queries.

  • Memory Management

    • Minimize object allocations and memory usage.

    • Use value types where appropriate.

    • Use the Dispose pattern for resources like database connections or FileStreams

    • Keep objects small and short lived. Keep resource heavy objects like dbconnections long-lived.

  • Leverage HTTP Caching

    • Use the attribute [ResponseCache(Duration = 300) on action methods. Here we cache the output for 5 minutes.

  • Minimize Round-Trips

    • Reduce the number of Http requests and database round trips.

    • Combine multiple database queries into a single-query.

  • Content Delivery Networks (CDNs)

    • Offload static assets to CDNs for faster delivery to users.

  • Compression

    • Enable GZip compression for HTTP responses to reduce data transfer size.

    • Use the AddResponseCompression middleware

  • Logging and Tracing

    • Use logging levels wisely.

    • Preferably log to a queue and let another process read it and add to the logs.

  • Optimize Assets

    • Optimize images and assets to reduce load times.

    • Minimize the number of external dependencies and libraries.

  • Benchmarking and Load Testing

  • Code Profiling and Perf Monitoring

    • Continuously monitor your application’s performance in production using tools like AppInsights, New Relic etc.

References