Yesterday we started our performance testing of our latest application and found one query taking 16 sec to execute. Using a combination of SQL profiler and JetBrains dotTrace (I blog on that later – it deserves it) We narrowed the problem down to not an ill performance SQL query but actually the built in CBO.FillCollection of DotNetNuke. Using reflection it is horribly slow, this query returned about 7000 rows with about 15 columns each. By implimenting a custom hydrator from Michael Washington’s blog this is now taking 200ms.
Quote:
In the Survey module I converted code such as this:
Public Shared Function GetSurveys(ByVal ModuleId As Integer) As List(Of SurveyInfo)
Return CBO.FillCollection(Of SurveyInfo)(DataProvider.Instance().GetSurveys(ModuleId))
End Function
To:
Public Shared Function GetSurveys(ByVal ModuleId As Integer) As List(Of SurveyInfo)
Dim SurveyInfolist As List(Of SurveyInfo) = New List(Of SurveyInfo)
Using dr As IDataReader = DataProvider.Instance().GetSurveys(ModuleId)
While dr.Read
Dim SurveyInfo As SurveyInfo = New SurveyInfo
SurveyInfo.SurveyId = Convert.ToInt32(dr(“SurveyId”))
SurveyInfo.Question = Convert.ToString(dr(“Question”))
SurveyInfo.OptionType = Convert.ToString(dr(“OptionType”))
SurveyInfo.ViewOrder = Convert.ToInt32(ConvertNullInteger(dr(“ViewOrder”)))
SurveyInfo.CreatedByUser = Convert.ToInt32(dr(“CreatedByUser”))
SurveyInfo.CreatedDate = Convert.ToDateTime(dr(“CreatedDate”))
SurveyInfolist.Add(SurveyInfo)
End While
End Using
Return SurveyInfolist
End Function
Public Shared Function ConvertNullInteger(ByVal Field As Object) As Integer
If Field Is DBNull.Value Then
Return 0
Else
Return Convert.ToInt32(Field)
End If
End Function