Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does <cfscript> improve performance setting application.cfm variables?

Status
Not open for further replies.

mokaplanjr

Technical User
Dec 20, 2000
33
US
I use the application.cfm template to set global variables (fonts, colors, etc.) using the tag <cfset application.variable = &quot;#data#&quot;>. The values of each variable come from a query of a table in the database.

I set about 30 variables this way and my ISP says this is bogging things down.

He said that I should use <cfscript> to set the variables from the query whenever there are more than 3 consecutive <cfset> tags. Something like:

<cfscript>
request.thing1=&quot;#query.thing1#&quot;;
request.thing2=&quot;#query.thing2#&quot;;
request.thing3=&quot;#query.thing3#&quot;;
request.thing4=&quot;#query.thing4#&quot;;
</cfscript>

I have seen nothing in docs or books that support this, but we have been getting some performance problems. The docs I have read state that <cfscript> was invented for those quite comfy working in a scripting lanquage environment, rather than tag-based, but nothing about performance.

Also, is there any convention in naming the variables? I had originally named them &quot;application.whatever&quot; and he suggested &quot;request.whatever&quot;, but I don't see any specific attributes required in the Big Blue Book O' CFML.

I ask this question with all due respect to the ISP's staff, but I'd like to see what other folks have run into in this regard.

I have set up a new template, complete with freshly-named application and cached query. Just seeking advice before I bring down the house (read: &quot;server&quot;) again.
 
I dunno if CFSCRIPT executes faster or not.

It does offer some things that regular CFML doesn't, like do while loops, but I haven't heard anything about executing faster.

Are you setting these values in Application.cfm, or are you setting them once and then re-checking to see if they're still loaded?

If you're going:

<cfset application.variable1=&quot;one&quot;>
<cfset application.variable2=&quot;two&quot;>

then, yeah, you're gonna be hogging up resources.

One approach would be to re-scope these to REQUEST.

<cfset request.variable1=&quot;one&quot;>
<cfset request.variable2=&quot;two&quot;>

THe REQUEST scope lives and dies by the page request. And, it is somewhat faster than APPLICATION. But, it is available to every level, and if you're going to use it, then you can use it in Application.cfm.

Another way would be to make load the variables into memory on the first call of Application.cfm, then test to make sure that they're still loaded.

<CFIF not isDefined(application.Variable1)>
<cfset application.variable1=&quot;one&quot;>
<cfset application.variable2=&quot;two&quot;>
</cfif>

Also, please note that when you're setting APPLICATION scope variable, you should lock them, otherwise they could be overwritten by something else. REQUEST scoped variable don't need to be locked, because they die at the completion of the page request.
 
Cool thread :)

I have seen several scripts that &quot;prove&quot; CFSCRIPT is faster than using several CFSET's so that was good advice.

Replacing Application scope with Request scope... well those two scopes are quite different so I wouldn't say they where interchangable. There is more info on the Request scope here:

Basically the Request scope is only alive for one user and one page (and any included files/custom tags)

As for &quot;Do While&quot; loops, they are available in &quot;regular&quot; CFLOOP tags..

Also, when dealing with Application variables you MUST use CFLOCK, failing to do this will crash your server!

Have a great Canada Day weekend!
 
Just letting dasniper and CFHub know I've read your posts and appreciate them. Meanwhile, I am using the information (unfortunately to go back and rework a completed and live site).

I will either post a &quot;thanks-it-works-great&quot; or a &quot;help-I-can't-get-rid-of-the-errors&quot; message as soon as I am done.

Hope your Canada Day was as fabulous as our July 4th.

º{>
 
hi mokaplanjr

CFSCRIPT, like any CF tag must be sent to the app server as part of the parsing process.

If you could move 10 CFSET statements to sit between CFSCRIPT only one CF tag would be sent to the app server instead of 10.

This absoluteley improves performance time, and reduces overhead.

 
Redid the variables in my application.cfm files to <cfscript>. And while it's generally difficult to tell the difference between zippy and zippier on my local development server, it went &quot;zing!&quot;

(I swear I could hear the &quot;zing&quot; sound, but it could be I just need a bacon cheeseburger.)

Thanks to all.

º{>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top