EasyCFM.COM ColdFusion Forums / Good Coding Tips! / Scoping variables. PART II

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Scoping variables. PART II

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

Lola
04-18-2005 @ 6:06 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 363
Joined: Feb 2005

I would just like to point out that scoping is extremely important. After I scoped all my variables in my app, the speed increase went from 98ms to 63-78ms. That is a huge difference for any developer.

Many developers forget to scope queries:

<cfloop query='variables.name'>
    #variables.name.column#
</cfloop>

Remember that even queries are under a variables scope, and so are user-defined functions. Many people forget about this,

#variables.udf()#

It will increase performance, I guarantee.


This message was edited by Lola on 4-21-05 @ 8:47 AM

Lossed
04-23-2005 @ 8:02 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 1095
Joined: Apr 2004

tks for this post Lola.
On one monstor(for me anyway) nested loops page with queries outside and one I had to put inside the loops, I went through and scoped everything. Execution times dropped from around 800ms to around 500ms. Wow, what a difference that made. Couldn't belive my eyes and had to run the same templates over and over to get some averages. It's a scehdueled task with some final writes to the application scope at the very end of the page. So the time didn't really matter on this page, but going through everything I've coded to date to scope everything is now high on my to-do list. Tks.


Lossed
---------------------------
When the only tool you have is a hammer, everything looks like a nail Smile
-----------------------------

Lola
04-23-2005 @ 9:24 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 363
Joined: Feb 2005

Your Welcome!

Just recently when I did some heavy optimization on my application, I dropped from around 110 ms to 32/31 ms JUST a few days ago.

I still expect to drop it to 15/16 ms when I do final stages on optimization, wow that would be awesome wouldn't it? When I first started I was around 200!

Anyway, yes, always scope your variables, it'll be less confusing, faster, and you can have more than 1 variable with the same name in different scopes.

If you want more on optimization, I started this little blog myself just yesterday:

http://cfsource.blogspot.com/

I will be adding articles daily, I should have new article on optimizing coldfusion code tonight, so bookmark it! Playful

Coldfusion optimization strategies and benchmarks:
http://cfsource.blogspot.com/


This message was edited by Lola on 4-23-05 @ 9:25 PM

Lossed
04-23-2005 @ 11:20 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 1095
Joined: Apr 2004

Will bookmark that page Smile .
I'm not sure now where I read it, maybe even one of your posts, but in case it wasn't you, It makes a difference not only scoping the vars in a loop but also the currentrow.
eg, this:

<cfoutput query="variables.qcolour">
#variables.qcolour.colourid[variables.qcolour.currentrow]# #variables.qcolour.colour[variables.qcolour.currentrow]# <br>
</cfoutput>

is consistently faster than:

<cfoutput query="variables.qcolour">
#variables.qcolour.colourid# #variables.qcolour.colour# <br>
</cfoutput>



Lossed
---------------------------
When the only tool you have is a hammer, everything looks like a nail Smile
-----------------------------

Lola
04-24-2005 @ 12:29 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 363
Joined: Feb 2005

Yes, ofcoarse, even that is scoped, everything can be scoped in coldfusion believe it or not Wink



Coldfusion optimization strategies and benchmarks:
http://cfsource.blogspot.com/


This message was edited by Lola on 4-24-05 @ 12:29 AM

edge
07-07-2005 @ 12:57 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 140
Joined: May 2005

Wow, thanks Lola!!

I need to do a GOOD BIT of optomization on ours, I've had to code everything so fast and make so many changes (small company, new company, everything changes) that things tend to get messy.

If you haven't already (I'm bookmarking as I type), perhaps an article that would help someone like me go from file #1 to file #XXXX would help.

Either way, it'll be greatly appreciated Smile

edge
07-07-2005 @ 12:58 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 140
Joined: May 2005

EEK!

Blog's down Frown



JJfutbol
07-07-2005 @ 7:13 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1250
Joined: Nov 2004

Aye his blog is down and hasn't kept it up. I'm not sure why Lola hasn't kept at it. He only made 2 posts on the blog and that was it. Frown  Luckily I saved a copy on my computer. He made some really good tips. I think he would do real well if he kept it going.

----------------------------------------------------
Need FREE CF applications?? Then my site has it all, http://www.mygamingnation.com/downloads.cfm In time I will be including many more free CF apps as you will see many listed up top on that page.


Website Designed and Developed by Pablo Varando.