Building Performance into Internet Applications


Cross Boundary COM/COM+Calls
Frequently used object data should be saved within script variables. This will cut down on COM method calls, which are relatively expensive, compared to accessing script variables. COM calls should be minimized from ASP pages to achieve optimal performance. It is better to write a few lines of ASP code than to wrap it within a COM component.

In practice, accessing COM properties or methods can be deceptively expensive. Here is an example, showing some fairly common code (syntactically speaking): =

If = Then ' ...

When this code runs, here's what happens:

  1. The variable "Foo" is resolved as a global object.
  2. The variable "bar" is resolved as a member of "Foo." This turns out to be a COM method call.
  3. The variable "blah" is resolved as a member of "". This, too, turns out to be a COM method call.
  4. The variable "qaz" is resolved as a member of Yes, this turns out to be a COM method call.
  5. Invoke "". One more COM method call. Get the picture?
  6. Do steps 1 through 3 again to resolve "baz". The system does not know if the call to "qaz" changed the object model, so steps 1 through 3 must be done again to resolve "baz".
  7. Resolve "baz" as a member of "". Do the property put.
  8. Do steps 1 through 3 again and resolve "zaq".
  9. Do steps 1 through 3 yet another time and resolve "abc".

As you can see, this is terribly inefficient and slow. The fast way to write this code in VBScript is

Set myobj = ' do the resolution of blah ONCE

Myobj.baz = myobj.qaz(1)

If Myobj.zaq = Then '...

If you're using VBScript 5.0 or later, you can write this using the With statement:


.baz = .qaz(1)

If .zaq = .abc Then '...


End With

Note that this tip also works with VB programming.

About the author

TechWell Contributor's picture TechWell Contributor

The opinions and positions expressed within these guest posts are those of the author alone and do not represent those of the TechWell Community Sites. Guest authors represent that they have the right to distribute this content and that such content is not violating the legal rights of others. If you would like to contribute content to a TechWell Community Site, email

About the author

Arvind Rajaram's picture Arvind Rajaram

Arvind Rajaram is a senior programmer analyst. He has more than five years' experience in software development, quality assurance, and automated testing. He has a master's degree in engineering from Brooklyn Polytechnic, NY, and has worked as a performance engineer for several projects. You can contact Arvind at

AgileConnection is one of the growing communities of the TechWell network.

Featuring fresh, insightful stories, is the place to go for what is happening in software development and delivery.  Join the conversation now!