1

I am maintaining a classic ASP application. It has some reports and few of them has around 25 columns and around 600 rows. I return the data from the server to the client over an AJAX call and display the results.

What I do is I create the HTML string for a table with the header and rows on the server side (using string concatenation) and do a response.write at the end.

if not rsStatus.eof then
        strresult=strresult & "<table class='sort-table' id='table-1'><thead><tr class='gridHeader' style='height:15px;'>"
        strresult=strresult & "<td>S.N.</td>"
        strresult=strresult & "<td>TSPL Job No.</td>"
        strresult=strresult & "<td>Client Name</td>"
        strresult=strresult & "<td>Job Type</td>"
        strresult=strresult & "<td>Govt Office</td>"
        strresult=strresult & "<td>Ref Value</td>"
        strresult=strresult & "<td>Govt File No.</td>"
        strresult=strresult & "<td>Submission Date</td>"
        strresult=strresult & "<td>Days Elasped Since Filing Date</td>"
        strresult=strresult & "<td>Process-Cycle/Status stage</td>"
        strresult=strresult & "<td>Status/  Remarks</td>"
        strresult=strresult & "<td>Status Last Updated on</td>"
        strresult=strresult & "<td>Trigon Bill No</td>"
        strresult=strresult & "<td>Trigon Bill Date</td>"
        strresult=strresult & "<td>Payment Received / Pending</td>"
        strresult=strresult & "</thead></tr><tbody>"
        dim rownum
        rownum = 1
        while not rsStatus.eof
            strresult=strresult & "<tr class='gridrow " & IIf(rownum Mod 2=1,"bgodd","bgeven") &"'>"
            strresult=strresult & "<td>" & rownum & "</td>"
            strresult=strresult & "<td><a href='http://localhost/app/global/weblets/Jobdetails.asp?JobId=" & rsStatus("iJobId") & "' target='new'>" & rsStatus("vJobNo") & "</a></td>"
            strresult=strresult & "<td>" & rsStatus("Client") & "</td>"
            strresult=strresult & "<td>" & rsStatus("vJobType") & "</td>"
            strresult=strresult & "<td>" & rsStatus("GovtOffice") & "</td>"
            strresult=strresult & "<td>" & rsStatus("RefVal") & "</td>"
            strresult=strresult & "<td>" & rsStatus("FileNo") & "</td>"
            strresult=strresult & "<td>" & rsStatus("SubmitedOn") & "</td>"
            strresult=strresult & "<td>" & rsStatus("elapsed") & "</td>"
            strresult=strresult & "<td>" & rsStatus("CurrentStatus") & "</td>"
            strresult=strresult & "<td>" & rsStatus("comment") & "</td>"
            strresult=strresult & "<td>" & rsStatus("dStatusDate") & "</td>"
            strresult=strresult & "<td>" & rsStatus("BillNo") & "</td>"
            strresult=strresult & "<td>" & rsStatus("BillDate") & "</td>"
            strresult=strresult & "<td>" & rsStatus("PymtStatus") & "</td>"
            strresult=strresult & "</tr>"
            rownum = rownum+1
            rsStatus.movenext
        wend
        strresult=strresult & "</tbody></table>"
    else
        strresult=strresult & "<tr class='gridrow'><td colspan=3>No Status Present for the Job</td></tr>"
    end if
    Response.Write(strresult)

The performance is not very good as the no of rows is increasing.

What might be a better way to do it?

Kangkan
  • 15,267
  • 10
  • 70
  • 113
  • 1
    Are you positive that the slow-down is the snippet of code you've shown? Could it be the cursor that fetches the rows? Or client-side script that works on all rows? Also, if you're returning all this in an AJAX call, why don't you move all the markup to the client page/HTML, return just the data (in JSON)? – G. Stoynev Apr 02 '13 at 14:39
  • @G.Stoynev: I was looking for suggestion that you are proposing. But, I wanted to understand if JSON will speed up the response. I know, the table structure might also delay the rendering on the client side. I have observed that the SQL server behind returns the data much earlier, but the client keep waiting for the entire data. In JSON, i need to send the field name with every value, whereas in this I am sending the values only. – Kangkan Apr 03 '13 at 07:01
  • 1
    In fact in JSON you won't be sending the field name, nor the markup, so it'll be less than the current string length. Plus you'll spare all the concatenations, which @MaxiWheat points out as a slow-down factor. – G. Stoynev Apr 03 '13 at 13:32
  • Thanks @G.Stoynev. Any clue how I may be able to send JSON from the server side using classic ASP? – Kangkan Apr 04 '13 at 05:24
  • 1
    You need to prepare JSON-formatted string and Response.Write it to the client. There are many libraries that help with the formatting - see my answer to [this SO question](http://stackoverflow.com/questions/15689469/web-services-classic-asp/15696891#15696891) – G. Stoynev Apr 04 '13 at 12:47

3 Answers3

2

String concatenation in VBScript has really poor performance, you could try to improve your script using methods described in those articles.

The most simple case is to create an array with all the strings in it, and then call Join to concatenate them all.

Hope it helps

MaxiWheat
  • 6,133
  • 6
  • 47
  • 76
1

No need to build up a string, just write out the lines.

e.g.

<% if not rsStatus.eof then %>
        <table>
            <tr>
                <td>S.N.</td>
            </tr>
        </table>
<% end if %>
Roisin
  • 11
  • 1
0

Just wanted to add an answer to my own question here as this gave me a good performance enhancement.

I converted my SQL queries to for xml queries with every column as 'td' like this:

Select col1 as [td], col2 as [td], col3 as [td] from table for xmpl path('tr'), root('table')

and returned the result back to the browser with almost no handling on the ASP server side code.

Kangkan
  • 15,267
  • 10
  • 70
  • 113