Reputation: 3
I have a .aspx screen that displays some data in an asp:GridView component. There can be up to approx 30k records returned when page loads. it is taking appr 30 sec to retrieve the 13000 records from the database.IS this slow or fast? am using stored procedure to retrieve the records from the database n am querying the database only once and storing it. then there is a foreach loop which is taking more than 2 mins to execute? so it taking aapr 4 min to load the page.
I am just a beginner to asp.net .can you please help me out to improve the delay in when page loads?
here is the looping structure ..can we optimize it in any way?
List auditList = retrievedatafromdatabase();//This method returns records from database
foreach (Entity obj in auditList)
{
obj.CultSpecificRevisedData = "NULL";
obj.CultSpecificPublishedData = "NULL";
if (obj.RevisedData != null && obj.RevisedData != "NULL")
obj.CultSpecificRevisedData = ConvertToProfileSpecificFormat(Convert.ToDecimal(obj.RevisedData), DecimalSeparator);
if (obj.PublishedData != null && obj.PublishedData != "NULL")
obj.CultSpecificPublishedData = ConvertToProfileSpecificFormat(Convert.ToDecimal(obj.PublishedData), DecimalSeparator);
var yearPart = obj.CalendarYear;
var monthPart = string.Empty;
var frequencyName = GetEnglishFrequencyBame(frequencyTypeMasId);
if (frequencyName == FrequencyType.Monthly)
{
monthPart = new DateTime(obj.CalendarYear, GetMonthNumber(obj.Month), 1).ToString("MMM");
obj.CultSpecificPeriod = monthPart + "-" + yearPart.ToString();
}
if (frequencyName == FrequencyType.Quarterly)
{
UserMessage = obj.QuarterName;
obj.CultSpecificPeriod = UserMessage + "-" + yearPart.ToString();
}
else if (frequencyName == FrequencyType.BiAnnually)
{
UserMessage = obj.SemesterName;
obj.CultSpecificPeriod = UserMessage + "-" + yearPart.ToString();
}
else
{
obj.CultSpecificPeriod = yearPart.ToString();
}
}
Upvotes: 0
Views: 149
Reputation: 416131
I'll echo comments about not really needing 30K records. Research shows that humans can't really visually process anything more than about 2000 list items, and if you're showing more than this you're effectively lying to your users by encouraging them to get a false or incomplete sense of the data.
But if you persist in doing this, what you want to do is iterate through the records set by hand, use Response.Write() to manually compose the html for each row and send it to the browser, and then use a counter to call Response.Flush() every now and then. Bonus points if your data layer supports streaming the data from your database as well (ie: via a datareader) rather than loading the entire result set into RAM.
Upvotes: 0
Reputation: 10712
Paging is your first option.
But you should consinder the following: Do you really need 30K records ? users don't usually go through the first 10\20 records, try returning only the first 100\1000 and giving good search and filter capabilities that will limit the result set scientifically.
I had the same problem and I understood that the users dose not need that many results they need a good way of finding what they want out of these results.
of course that could be incorporated together with paging.
If paging dosen't suit your solution (for some reason) The you do not agree with what was said, post some code and we'll try to help with performance optimization. keep in mind that it's a very hard task sometimes.
Upvotes: 2