ASP.net: Repeater vs. Dynamic Creation of Table vs. StringBuilder - Performance question
The problem: My company currently has a query that takes roughly 3 seconds to run, but the table creation to display the data takes roughly 30 seconds to loop through. Most of it is simply:
Dim MainTable as New Table
Dim TableR as New TableRow
Dim TableC as New TableCell
TableCell.Text = "Some data"
TableRow.Controls.Add(TableC)
MainTable.Controls.Add(TableR)
Now, the performance of this operation is about 30 seconds on roughly 550 records. I tried changing the process to using Strings instead:
开发者_StackOverflowBuilder.Append("<tr><td>Something</td></tr>")
But there was no real improvement. My question is in regards to trying to improve the performance.
Would a repeater actually be faster?
Are you sure you know where the bottleneck is? You should measure the actual loop execution, the time it takes to fulfill the client request, and the time it takes the client to render the page.
It doesn't seem likely that it would take a StringBuilder
loop thirty seconds for 550 iterations, unless you're performing a different, unusually expensive operation within the loop.
It's more likely that the performance hit is due to:
1) Excessive time sending the data from the server to the browser.
2) The client taking a long time to actually render the page.
Both of these typically have the same cause - the HTML you're sending the browser is too big. (Which could also be cause by saving a ton of stuff in ViewState
, which inflates the amount of data you send to the client.) Whatever the case, you need to take those measurements first to find out where the problem is.
Did you try to bind the data to a gridview object ?
I just answered another question where the user was having similar issues trying to bind to 2k+ records. Maybe there is some pointers there that will help you improve the speed of things:
Asp.net binding big dataview to DataGrid
精彩评论