New Application.cfc flag to disable searching query result sets for unscoped variables, since

There is a new Application.cfc flag in 5.3.8 to disable searching thru query result sets for unscoped variables. This applies when you are looping thru a query, i.e with <cfoutput query="q">.

There was already an option in the admin, under Settings, Scopes. but you can now also configure this directly via code per Application.

// Application.cfc
// or 

By default, in cfml, query results are searched for unscoped variables before some other scopes, which can be a performance bottle neck, especially when working with queries with a lot of columns which need to be searched. When this flag is set, this is bypassed. If you do enable this, you need to refer to each query column with it’s scope.

i.e. #q.username# rather than just #username#

The cfml scope search order for unscoped variables is as following

Unscoped variables are a performance killer, you can use the built in debugging to identify when this is a performance problem via the Implicit variable Access section.

I have written the following Lucee Admin Extension which aggregates all the debugging statistics in a single report so you can see if you are experiencing any problems with overhead from unscoped variables.


A quick example

    a = "variable";
    q1 = QueryNew("a,b,c,d");
    QuerySetCell(q1, "a", "query");

<cfloop times=1000>
    <cfoutput query="q1">

With searchResults = true; #a# outputs ‘query’


With searchResults = false; #a# outputs ‘variable’



This is awesome! Amazing the kind of speed-difference it makes.

1 Like