Entity Framework Tracking and AsNoTracking query performance comparison with benchmarks

I modified Microsofts sample Entity Framework benchmark class to just look at the relative timing differences of tracking versus non tracking queries (eg. AsNoTracking).

The Tracking v AsNoTracking performance benchmarks were run on Entity Framework Core 6.01 and are simple and just involve pulling back 1K, 5K and 10K records from a DB that’s populated prior to each batch of benchmarks (one for each record amount).

We can see from the results below that the cost of tracking entities relative to not tracking them goes up as we track more and more, this is to be expected. What did surprise me was the size of the differences.. for example AsNoTracking performance is 3.56x faster than tracking when we are pulling back 5K entities.. which is a relatively small record set.

Click the image to open a larger view in a new window…Entity Framework Core AsNoTracking benchmarks

Note… when running benchmarks there can be so much variation between different machines and indeed different runs on the same machine. This means its important we look at the relative performance (eg. the Ratio column) of one benchmark compared to another and not focus too much on the absolute timings in the Mean column. Given we have a network latency aspect to the figures above this is even more important in this case.

Leave a Reply

Your email address will not be published. Required fields are marked *