Performance Question

Is there any difference in performance in a Web App to repeatedly reference a screen element or is it more efficient to reference it once into a variable then use that if you need to manipulate the data for other purposes.

Example:

Dim wk as string
Dim cnt as integer

for cnt = 0 to 4
   wk = ListBox1.Cell(ListBox1.ListIndex,0)
   wk = NthField(wk,";",cnt)
   '.... do something with wk here
next cnt

or this way

Dim wk1 as string
Dim wk2 as string
Dim cnt as integer


wk1 = ListBox1.Cell(ListBox1.ListIndex,0)
for cnt = 0 to 4
   wk2 = NthField(wk1,";",1)
   '.... do something with wk2 here
next cnt

AFAIK, there shouldn’t be any difference in the two. It’s doing a lot of array lookups which are pretty fast.

It’s been a long time since I’ve used NthField. They used to be incredibly expensive performance wise. If you’re doing additional NthField calls you might get better performance by using the Split command and moving it into an array during processing. Certainly getting wk2 BEFORE the loop will speed it up (since it’s getting the first index every time through the loop).

If this is a long calculation you might need to put it into a thread to keep the page responsive. Then you’d absolutely have to put the control values into some sort of storage.

Yep I was aware of NthField being “expensive” but I use it when it is not called repeatedly. It was probably bad to use it in this example.

I was more interested in repeated references to the screen control or is it more efficient to reference it once and then manipulate local variables. I assume that is what you reference in your first line. So in practice the screen control data is mirrored in some data structure on the server in a way similar to any other local variable and there is not some “expensive” algorithm to find it and return a value.

Thanks.

Remember that ALL processing is done on the server. The browser sends back events and that’s it. There’s nothing on the server end that requires a round trip messaging to the browser.