Thursday, November 30, 2006

Avoiding the Evaluate function

There is a good description about what is going on with the use of the evaluate function behind the scenes.

I still have one question after reading this that I'm sure somebody has already investigated. Do we pay the extra overhead for each occurrence of evaluate in a page, or just once? I don't mind so much if I'm just paying it once for 50 instances on a page. If the parser is getting invoked 50 times, I think I'm hunting them down and changing them.

ColdFusion MX 7 -- Avoiding the Evaluate function -- Version 7

4 comments:

  1. because of the nature of evaluate, and the basics of what it is doing, I would tend to say that the parser is getting involved in every instance. And because of the workarounds available for almost every instance where evaluate may be necessary, I would go through and hunt them down and change them. just my two cents.

    ReplyDelete
  2. That sounds reasonable. Would you still resort to using evaluate for something like dynamically determining and executing a method name? Is there a workaround for something like that?

    ReplyDelete
  3. Thanks for pointing out this technique. Unfortunately I can't get it to work for replacing evaluated dynamic queries. e.g.

    <CFIF Evaluate("#myQuery#.firstname") is "Fred">
    <--- some code --->
    </CFIF>

    ReplyDelete
  4. @Gary - That's right. You can't easily replace the evaluate function in all cases. While there is probably a way to do what want without the evaluate, it's not a trivial change like changing some brackets.

    The bigger issue we're having is that you have to do about 100,000 simple evaluates to start to notice a consistent difference.

    ReplyDelete