Alex Rivera | Logout

What causes EF insert to be much slower than plain ADO.NET?

Asked 2012-08-01T00:35:47.937
13

I have to record web service calling in database. At beginning, I used code first EF to define Entity class and generate database script. The database part is very simple, just only one table. There is a primary key: Id, and other columns are string ,datetime and float. 16 columns totally.

Then I ran the performance analysis of VS2012. the report shows RecordUsageEF consume half time of whole calling, that is ridiculous. I tried MergeOption.NoTracking option and Pre-Generate Views(How to: Pre-Generate Views to Improve Query Performance). But they didn't help to much.

Then I tried Ado.net. I put sql script in source code just for testing. calling 2 methods together to compare the performance.

    public static void RecordUsage(HttpContext httpContext, XmlWDCRecipe processedRecipe, string orgRecipe, string userName, ActionEnum action, bool trueview, string pageId)
    {                                                                                               
        RecordUsageEF(httpContext, processedRecipe, orgRecipe, userName, action, trueview, pageId);
        RecordUsageADO(httpContext, processedRecipe, orgRecipe, userName, action, trueview, pageId);
    }

The result surprised me:
enter image description here

Updated using static EF context improves some:
enter image description here

Inside RecordUsageEF:
enter image description here

Updated Inside RecordUsageEF -- static context
enter image description here

Updated Just realized the default Performance is CPU sampling, here is the result when choosing Instrumentation
<

Edit
Report

1 Answer

2

Entity Framework is abstracting a lot of details as the cost of (some) CPU performance. Microsoft has an article detailing performance considerations: Performance Considerations (Entity Framework)

answered 2012-08-03T16:04:54.083

Your Answer