Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow EF profiling performance with mvc-mini-profiler

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.

like image 530
WVDominick Avatar asked Jun 22 '11 12:06

WVDominick


1 Answers

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;
like image 72
Jarrod Dixon Avatar answered Oct 13 '22 00:10

Jarrod Dixon