9

When I create my context using the below function the profiler shows about a 300ms increase from the standard EF (version 4) context creation method. Is there another way to do this that has better performance? It defeats the purpose of performance profiling as is.

    public static Models.MyEntities GetContext()
    {
        var profiler = MiniProfiler.Current;
        var sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString);
        var profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(sqlConn, profiler);
        return ObjectContextUtils.CreateObjectContext<Models.MyEntities>(profiledConnection);
    }

This first one is using the above function to create the context. The second is using the standard EF context creation method. Here is the difference in performance using the mvc-mini-profiler:

Profiler EF Context: 89.1
Some DB Hit: 317.9

Normal EF Context: 0.1
Some DB Hit: 7.4

UPDATE 2: I did some profiling in Visual Studio and it looks like the main time consuming operation is MvcMiniProfiler.Helpers.StackTraceSnippet.Get() and inside it there is a call to System.Diagnostics.StackTrace..ctor(bool). This takes a long time to complete and seems to be the cause of the above delay.

WVDominick
  • 2,074
  • 15
  • 17
  • Well, the (non-mini) profiler should show you where the problem is, right? – Craig Stuntz Jun 22 '11 at 13:29
  • Craig, I'm not sure what you are getting at. The profiler context is slowing things down. I'm trying to determine if it's something I'm doing wrong in my context creation function. – WVDominick Jun 22 '11 at 13:45
  • If you think the mini profiler is slowing things down, use a real profiler -- like the one built into VS -- to diagnose the problem. – Craig Stuntz Jun 22 '11 at 13:53
  • Thanks for the suggestion, Craig, but I want to use this profiler because I can easily add it to a production system and see live numbers. I just like the way they made it. Very slick. – WVDominick Jun 23 '11 at 12:00
  • I'm not telling you to not use the mini profiler. I'm suggesting a way you could diagnose the problem it's causing. – Craig Stuntz Jun 23 '11 at 13:19
  • 1
    How many queries are being profiled? – Jarrod Dixon Jun 29 '11 at 23:36
  • As stated below it slows down for the first query executed and all others run just fine. This wouldn't be too bad, but I have lots of AJAX requests that open separate contexts. – WVDominick Jul 01 '11 at 12:17
  • 1
    once we figure this out ... we will be good http://stackoverflow.com/questions/6613180/how-do-i-correctly-profile-entity-framework – Sam Saffron Jul 07 '11 at 15:51
  • also .... if **anyone** can provide a standalone simple repro solution I will be happy to profile it. – Sam Saffron Jul 09 '11 at 11:02
  • I believe whatever was making this happen has since been repaired – Sam Saffron Aug 28 '11 at 11:33

1 Answers1

5

I've pushed a changeset to the profiler that allows disabling of stack traces, since lots of queries could impact profiling.

Just set the following setting during application start:

MiniProfiler.Settings.ExcludeStackTraceSnippetFromSqlTimings = true;
Jarrod Dixon
  • 15,727
  • 9
  • 60
  • 72
  • 1
    Now it appears that it's only the first query after the profiler context is defined that runs slowly. After the first LINQ statement is executed the rest go without slowdown. I can see that the stack traces aren't being executed on the queries not, but something else appears to be slowing down the initial query. – WVDominick Jul 01 '11 at 12:15
  • FWIW, I am seeing drastic slowdowns as well. Page loads are spiking up to 10 seconds when I have the profiler enabled. I pulled the lastest change set and it did not seem to improve things. – jslatts Jul 01 '11 at 21:29
  • @WVDominick can you run the built in profiler again to see where it is stuck? – Sam Saffron Jul 09 '11 at 11:03