Why is DbContext.SaveChanges 10x slower in debug mode Why is DbContext.SaveChanges 10x slower in debug mode asp.net asp.net

Why is DbContext.SaveChanges 10x slower in debug mode


Whohoo!

Ok, so the reason debug mode was exceptionally slow was because Visual Studio's Intellitrace was recording each ADO.NET event ( all 20, 000 of them ) generated by Entity Framework.

So Tools-> Options -> IntelliTrace and Uncheck "Enable IntelliTrace" fixed the issue.

Or one can also just filter out the ADO.NET events by going to Tools->Options -> IntelliTrace -> IntelliTrace Events and uncheck ADO.NET

Thanks for everyone's suggestions.

A section here talks about Will Intellitrace slow down my app

How to Filter IntelliTrace Events


There are multiple performance considerations for EF and it's known that, compared to many others orm's, operations can be slower than expected/desired for an orm.

(1st) when running on debug will always be slower and (2nd) first run after building will always be slower.

All of this may depend on the complexity of your model. Try to capture the T-SQL statements using SQL Profiler.


As stated in comments, the given answer only works for Visual Studio Ultimate.

As of VS2019 (and probably most other version), the solution is via:

Tools > Options > Debugging > General

Then uncheck Enable Diagnostic Tools while Debugging.

Of course, you'll lose all the diagnostic bits and bats, but it speeds Entity Framework up immensely if that's what you're after.

Update:

The above solution stopped working for me. I've found that I needed to further uncheck Show elapsed time PerfTip while debugging from that same list of options.