Can somebody explain
In debug mode, my webpage takes 116 seconds to load versus 15 seconds if I start the project without debugging.
I have set trace statements and identified that ~100 of the 116 seconds is spent in my DbContext.SaveChanges method when in debug mode.
Running the project without debugging only 7 seconds in spent in the same section.
Let me know in the comments if you'd like more information..
Project Setup:
Additional Info: (Let me know in the comments if you need more)
Update:
As @ruionwriting suggested, I profiled the database and what I found is that the ~20,000 sql commands take exactly the same time whether the project is run in debug or production mode. ( 0 ms per command).
However, the absolute time difference on average between the 20,000 commands is 5ms in debug mode.
Contrasted with production mode, the average time difference over the set of commands is 0.3 ms.
This is the approximate 10x time performance difference and isolates entity framework as what is taking the extra time in debug mode.
Is there a way to configure the debug build such that EntityFramework can be referenced without debugging flags?
And if I were to somehow achieve the performance back through some compiler magic, what would I lose in terms of debugging capabilities? Currently I can't step into entity framework code so I don't think I would miss anything.
Thanks!
Because there are 400,000 loops in your code that need to be executed in debug, but these loops are optimized in release mode, so there is a big difference in the execution time. This difference will change with the number of cycles.
Unfortunately, debugger speed has some runtime limitations, which can't be easily fixed. If your code does some high performance computations, Debugger will be at least 3 times slower than usual Run.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With