title: Performance tips for classic asp?
body: <p>Today I was tasked to improve the performance of a classic ASP page. Rewriting the code in ASP.NET is at this moment not an option so I took up the challenge to squeeze every ounce of performance I can get out of the page.</p>
  
  <p>The page consists of the basic "SELECT bla bla FROM bla" into a couple of recordssets. A while loop iterates through those recordsets and dumps &lt;tr&gt;&lt;td&gt; strings. Within the while loop there is a bunch of conditionals and whatnot. There are 3 subroutines that are called which use global variables (not local variables passed as parameters).</p>
  
  <p>So nothing really shocking or anything. Before I started my optimization the loop took around 15 seconds to complete. Of the 15 seconds around 6 were taken up by the sql query.</p>
  
  <p>After changing a few things around I managed to get it around to 7 seconds. </p>
  
  <p>The things that I have changed around are:</p>
  
  <ul>
  <li><p>Instead of doing SELECT *, I selected only the columns that I needed. The query went down to on average 4 seconds. It's a pretty heavy query with views within views.</p></li>
  <li><p>I removed all the context switching within the loop. So I changed things like &lt;%= bla %> to Response.Write(bla). </p></li>
  <li><p>The 3 subroutines were defined as functions, but they were used as sub (with no result). So I changed the functions to subs. Does that help?</p></li>
  </ul>
  
  <p>After making my changes I found that most of the time was taken up by one of the subroutines. I didn't have time enough today to change the subroutine, but it consists of things like:</p>
  
  <ul>
  <li>Date functions: Dateadd, Datediff</li>
  <li>Array functions: Ubound(arr) and index referencing: arr(I)</li>
  <li>String functions: left, mid, right, lower, replace</li>
  </ul>
  
  <p>With every page call, that subroutine is run around 1600 times. </p>
  
  <p>Anybody out there have any experience with optimizing classic asp pages? Do you have any good tips for optimization? What I'm looking for is improvement of code within a do ... loop statement.</p>
  
  <p>I'm an experienced ASP.NET developer and know quite a bit about perfomance improvement in ASP.NET. Classic ASP uses a different "engine" so I was wondering if anybody out there have any insights into improving the performance of classic ASP.</p>
  
  <p>Thanks!</p>
  
  <p>M</p>
  
  <p>PS: Yes I know that classic ASP uses VBScript</p>