Improve performance via optimized EF Core usage #76

Closed
opened 5 months ago by kimimaru · 1 comments
Owner

There are several ways we can improve the performance of our queries via Entity Framework Core. This article is several years old at this time, but it's still relevant.

In short:

  • Disable change tracking for read-only queries.
  • Load data eagerly if it's known which data is required (Ex. Use context.Users.Include(u => u.Stats) if reading from the UserStats table).
  • For very expensive queries, consider writing them in raw SQL (via context.Users.FromSqlRaw). This should be performed only as a last resort.
There are several ways we can improve the performance of our queries via Entity Framework Core. [This article](http://dotnetblogpost.com/2017/11/19/entity-framework-core-performance-tips-disable-tracking-queries/) is several years old at this time, but it's still relevant. In short: * **Disable change tracking for read-only queries.** * Load data eagerly if it's known which data is required (Ex. Use `context.Users.Include(u => u.Stats)` if reading from the `UserStats` table). * For very expensive queries, consider writing them in raw SQL (via `context.Users.FromSqlRaw`). **This should be performed only as a last resort.**
kimimaru added the
refactor
label 5 months ago
kimimaru added this to the TRBot 2.4 project 5 months ago
Poster
Owner

A good chunk of this is completed in c45e59dbbe for the important parts.

There's plenty more to do, but the hotspots have shown improvements. One host had about a 1 second delay between when the input message was received and carried out. These changes completely eliminated that delay.

A good chunk of this is completed in https://codeberg.org/kimimaru/TRBot/commit/c45e59dbbe90da2a86c75352b6d54266f4351012 for the important parts. There's plenty more to do, but the hotspots have shown improvements. One host had about a 1 second delay between when the input message was received and carried out. These changes completely eliminated that delay.
kimimaru closed this issue 5 months ago
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.