Speed Scripting

Posted: 1st September 1999 | Filed under: Press Articles, Technical
Author: Paul Ockenden

This article was originally published in PC Pro and is reproduced with permission.

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 Then

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 Then

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.

All articles Copyright CST Group Limited ©1997-2024

Let's Talk

Whether you have a new or existing project, we’d love to hear from you.

Our experienced team thrive on problem solving and working with your business goals in mind.

Get in touch

Cookie preferences

We'd like to know more about the pages you visit on our site to help improve it. If you're happy for us to collect this information please click accept all. Our full Privacy policy can be found here.