Journal

Speed Scripting

PC Pro logo Posted: 1st September 1999 | Filed under: Press Articles, Technical
Author: Paul Ockenden, Chairman of CST Group
First Appeared in PC Pro 1999

Barry Nile emailed us to say that he had recently upgraded his Web site, adding some of the ASP database techniques that we showed a few months ago, but now his site is a lot slower. In fact, he describes it as running like treacle. He wants to know what he can do - apart from buying a faster server - to make things become zippy again. Well, assuming that Barry has done all the usual stuff like making sure that he hasn't got any redundant loops or things like that, there are still several more techniques that he can use to get some speed back.

First, access to certain kinds of data can be very slow, and in particular, retrieving data from objects can have quite an impact on the speed of your application. The trick is to make sure that, where you'll be using this data several times, you copy it to a local variable first. So rather than saying:


If Request.ServerVariables("REMOTE_ ADDR") = whatever

at five or six different places within your code, you should instead assign the remote address to a local variable, so:


remote = Request. ServerVariables("REMOTE_ADDR")

and then use this in your 'if' statements:


If remote = whatever

This optimisation doesn't just work for the Request object, but will pay major dividends with ADO database accesses, session variables and many third-party installable components too. It'll obviously work well whenever a component has to go off and drag data from a disk file or the registry.

The second worthwhile optimisation for just about any ASP application is to turn off the session-tracking facility for pages that don't use session variables. You do this by putting:


<%@ENABLESESSIONSTATE = False%>

at the top of any such pages. The reason why this has such a dramatic effect on performance is that session tracking involves the use of cookies with tracking code on the server. Combining both these tricks should have quite an impact on speed.