« My Xojo Web App does … | Home | MBS Xojo / Real Studi… »

Tip of the day: Use more local variables


Speed
Using local variables to cache values you query often can speed up an app a lot. For example in a web app, if you use a loop of code and you access the current session with the session function, you waste a lot of time. Just an example:

for i as integer = 1 to 1000
Session.t.test
next

and this code is 10 times faster:

dim t as test = Session.t
for i as integer = 1 to 1000
t.test
next

Same applies for arrays where it's often better to lookup the value once in a loop.

Debugging
Another reason for local variables can be to see them in the debugger. For the runtime speed of your app it doesn't really matter if a value is stored locally. In a lot of projects I have code like this:

dim db as database = Session.db

So I can see the local properties of the database right there in debugger.
29 06 13 - 10:32
one comment

Great advice.
John in Louisiana - 29 06 13 - 20:25


  
Remember personal info?

Emoticons / Textile


Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.