What is happening in debug compilation that is causing the query to take longer to execute?

ぃ、小莉子 提交于 2020-01-05 09:37:49

问题


ServiceStack 3.9.69 via Nuget using SqlServer OrmLite dialect

I'm attempting to execute a parameterized stored procedure but am noticing an unusual slowness when the compilation mode is set to debug. The method that is slow is ConvertToList below:

    Dim result = Db.Exec(Of List(Of Dto.FieldSample))(
        Function(cmd)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "up_GetFieldSample"
            cmd.Parameters.Add(New SqlClient.SqlParameter("@uploadID", uploadId))
            Dim reader = cmd.ExecuteReader()

            Dim converted = reader.ConvertToList(Of Dto.FieldSample)()

            Return converted
        End Function)

(I know there is a .SqlList extension available, but I tried that first with the same results. I switched to Exec to get a better idea of where the issue was)

The stored procedure returns in 2-3 seconds when executed in non-debug mode, but 15-20 seconds in debug mode. I understand that there is often tracing, etc included in debug compilation but I'm trying to figure out what is actually so slow.

What is happening in debug compilation that is causing the query to take longer to execute?


回答1:


As I suspected, there is some internal error handling/logging being performed during ConvertToList when it calls PopulateWithSqlReader Source

The underlying issue was a data type mismatch between my POCO (decimal?) and the database (int). It wasn't until I hooked up a LogManager.LogFactory = New ConsoleLogFactory() that I could see that an exception was being thrown internally, logged, then moving on. The 235+ (rows) of exception handling was what was causing the delay.



来源:https://stackoverflow.com/questions/19611495/what-is-happening-in-debug-compilation-that-is-causing-the-query-to-take-longer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!