Query Tracking vs. No-Tracking

Understanding how Entity Framework Core's change tracker impacts performance

Why You Need to See This! 🚀

Alright, let's talk real-world performance. You know how Entity Framework (EF) Core is awesome because it automatically handles updates? Well, that magic comes at a small cost: **tracking**. Every time you grab data, EF Core starts watching it, which is great for saving changes later, but totally unnecessary if you're just displaying the data on a web page!

This demo proves how cool it is to use **.AsNoTracking()**. It tells EF, "Hey, I'm just looking, don't worry about keeping tabs." The result? **Faster queries and less memory usage.** It's like switching off GPS when you only need a map—simple, but surprisingly effective for making your applications feel super snappy! Check out the numbers below to see the massive performance difference.

Tracked Query (Default)

Execution Time:

**9 ms**

**Purpose:** The default mode. Objects are tracked by EF Core's **Change Tracker**. This is necessary **only if you plan to modify and save** the entities later.

No-Tracking Query

Execution Time:

**17 ms**

**Purpose:** Objects are NOT tracked. **Ideal for read-only scenarios** like displaying data on a web page, reporting, or API responses.

The Bottom Line: Performance Win! 🎉

The No-Tracking approach was significantly better, showing a performance improvement of **-88.89%** over the tracked query!