Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does code written inside cfscript execute faster than the equivalent tag based code?

Today when I was trying to enhance the performance of my application, as per the suggestion of some ColdFusion developers, I modified some of the tag based code to cfscript based code.

But I did not see any performance enhancement. It actually seems a bit slower.

like image 676
Deepak Kumar Padhy Avatar asked Jul 03 '13 06:07

Deepak Kumar Padhy


1 Answers

It used to be the case up to - I think - CFMX7 that most CFScript constructs were quicker than their tag-based equivalents. And sometimes there was a significant difference. Since then though, there's really been nothing in it, and indeed CFScript code can sometimes be slower than the nearest equivalent in tags. For example:

for (i=1; i <= myObj.methodReturningTotal(); i++){
    // stuff here
}

vs:

<cfloop index="i" from="1" to="#myObj.methodReturningTotal()#">
   <!--- stuff here --->
</cfloop>

These look superficially the same, but the tag-based one will perform mre quickly because the myObj.methodReturningTotal() expression is evaluated every iteration for the for loop, but only once before the loop starts with the <cfloop> version.

Similarly looping over lists and queries using <cfloop> is slightly faster than using a combination of for / listLen() / listGetAt() for lists and similar shenanigans for queries.

Really... using different code constructs is not going to be a great place to get performance increases. The best place to look is to look at your logic to see if that can be improved, and - more likely to see gains - see how your DB interaction performs. Improving your SQL, looking at whether your indexes are right, etc, will get you more gains, because DB interaction is often the biggest performance bottle neck.

Good on you, btw, for being sceptical and questioning what your fellow CF developers had said, without providing any actual evidence. This is a good way to approach these things, and life in general.

like image 177
Adam Cameron Avatar answered Sep 21 '22 20:09

Adam Cameron