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%>
All articles Copyright CST Group Limited © 1997-2018
…provided us with extremely dedicated support over the years, Very responsive & knowledgeable.
— Khyati Patel, Malibu-Kahlúa International