12 EF Core performance tuning

 

This chapter covers

  • Deciding which performance issues to fix
  • Techniques for finding performance issues
  • Using patterns that promote good performance
  • Finding patterns that cause performance issues

This chapter is the first of two covering performance tuning your database accesses. Covering what, where, and how to improve your EF Core database code, this chapter is divided into three parts:

  • Part 1 —Understanding performance, the difference between speed and scalability, deciding what to performance tune, and determining the costs of performance tuning.
  • Part 2 —Techniques you can use to find performance issues and the use of EF Core’s logging to help you spot problems.
  • Part 3 —A whole range of database access patterns, both good and bad, to help you diagnose and fix many EF Core performance issues.

In chapter 13, you’ll apply the approaches shown in this chapter to the book app’s book list query. You’ll start by tuning EF Core code and then progress to more-complex techniques, such as using raw SQL commands to squeeze the best performance out of the database accesses.

12.1 Part 1—Deciding which performance issues to fix

Before describing how to find and fix performance issues, I want to provide an overview of the subject of performance. Although you can ignore performance at the start of a project, some concepts might help you later, when someone says, “The application is too slow—fix it.”

12.1.1 “Don’t performance tune too early” doesn’t mean you stop thinking

 
 

12.1.2 How do you decide what’s slow and needs performance tuning?

 
 
 
 

12.1.3 The cost of finding and fixing performance issues

 
 
 
 

12.2 Part 2—Techniques for diagnosing a performance issue

 
 

12.2.1 Stage 1: get a good overview—measuring the user’s experience

 
 
 

12.2.2 Stage 2: find all the database code involved in the feature you’re tuning

 
 

12.2.3 Stage 3: inspecting the SQL code to find poor performance

 
 

12.2.4 Techniques for finding database scalability issues

 
 

12.3 Part 3—Techniques for fixing performance issues

 
 
 

12.4 Using good patterns makes your application perform well

 
 

12.4.1 Using Select loading to load only the columns you need

 
 
 

12.4.2 Using paging and/or filtering of searches to reduce the rows you load

 
 

12.4.3 A warning that using lazy loading will affect database performance

 
 
 

12.4.4 Always adding the AsNoTracking method to read-only queries

 
 
 

12.4.5 Using the async version of EF Core commands to improve scalability

 
 
 
 

12.4.6 Ensuring that your database access code is isolated/decoupled

 
 
 
 

12.5 Performance antipatterns—database access

 
 

12.5.1 Not minimizing the number of calls to the database

 
 
 

12.5.2 Calling SaveChanges multiple times

 
 
 

12.5.3 Allowing too much of a data query to be moved into the software side

 
 
 

12.5.4 Not replacing suboptimal SQL translations with user-defined functions

 

12.5.5 Not precompiling queries that are used frequently

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage