All in the <head> – Ponderings and code by Drew McLellan –

Optimizing ASP

I spent a chunk of my day today optimizing an ASP script for performance. Here’s some observations I made that affect page build speed in a practical way.

The page I was working on was originally part of a prototype build to use an MS Access database. Therefore, the code was doing a rs.movefirst after opening each recordset on the page. This isn’t required for the SQL Server database we’re now using, and removing this line shaved a whole second off the build time. Neat.

After closing recordsets, it’s good practice to destroy the recordset object (by setting it to nothing) to release memory on the server. If you don’t manually destroy any objects, they get destroyed by the server on completion of building the page. Because of this, I have tended to be a bit sloppy in the past and allowed the server to do the hard work for me. What I discovered today was that manually destroying recordset objects as soon as you’re done with them has a positive impact on the page build speed. I’m not sure whether this has to do with the practicalities of resource handling or the efficiency of the server’s own trash collection code, but it certainly made a difference. I think I saved about 4/10 second on that alone.

If you think that saving one second here and 4/10 second there doesn’t really sound worth the effort, consider that an average ASP page will probably build in about 5/10 second …