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.9Normal EF Context: 0.1
Some DB Hit: 7.4UPDATE 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.
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;
精彩评论