Reputation: 1218
EF 6.0.1, code first, two tables (parent / child relation). I am using the model to query data inside a WebAPI and return the data (approx. 3KB) in JSON format to a website (I also tested the most simple ".FirstOrDefault()" query - does not make a difference here).
The first hit to the WebAPI ist slow (approx 10 seconds). This has nothing to do with the web site starting, the web site was already warmed up at that point. I implemented the same query via ADO and that takes about 1 second for the first hit. Subsequent requests show a much smaller Entity Framework penalty (about 190ms with EF vs. 170ms with ADO).
I tested this with the local sql server and Azure SQL, similar results. I profiled the local database: not much happening there, all 0 Duration requests. The Entity Framework produces additional queries to check for migrations, but those are lean. Looking at the profile output I noticed that all the database action seems to be happening within about one second, while the complete EF initialization process takes 10 seconds. Why?
I already found some hints here, like using Release Mode and turning on "Generate serialization" on, but that did not do much. Before I start implementing the obvious workaround (initializing EF early or just drop EF) I was hoping there are some other caveats I should check.
Upvotes: 3
Views: 2991
Reputation: 30628
There are known issues in Entity Framework 6.0.1 regarding startup performance, especially with the debugger attached. Details of this are discussed on the Entity Framework Blog, but since EF6.0.2 is marked stable, your first action should be to update to using that.
In general, there will always be some startup delay with EF6 vs querying directly in ADO, as it needs to load things related to the model, which you don't need to do when using ADO directly. However, it does appear that this is worse than normal on EF6.0.1.
Upvotes: 2