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

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. [LDEV-2772] - Lucee

// Application.cfc
this.searchResults=false;
// or 
this.searchQueries=false;

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.

https://lucee.daemonite.io/t/optimizing-your-code-scope-cascading/428

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.

5 Likes

A quick example

<cfscript>
    a = "variable";
    q1 = QueryNew("a,b,c,d");
    QueryAddRow(q1);
    QuerySetCell(q1, "a", "query");
</cfscript>

<cfloop times=1000>
    <cfoutput query="q1">
        #a#
    </cfoutput>
</cfloop>

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

image

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

image

3 Likes

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

1 Like