Prerequisite knowledge
This article does not require you to be an expert in ColdFusion. A general understanding of ColdFusion tags and other core language syntax is enough to get most out of this article.
User level
Required products
Adobe ColdFusion Enterprise Edition (2016 release) (Download trial)
Milan Chandna

15 March 2016


Adobe ColdFusion 2016 comes with a wide range of enhancements to CFML for better performance and productivity.
New language constructs like safe navigation and ordered structs greatly improve the productivity of CFML developers. Features like unscynchronized arrays, passing arrays by reference, and explicit scope lookup enhance the performance of applications. 

Safe Navigation

Previously in your ColdFusion applications, you used safe checks as shown below:
if(isDefined(“myvar”) && !isNull(myvar))
If you used nested structs, there were multiple checks in the struct.
In ColdFusion (2016 release), there is safe navigation as shown below:
The hook operator(?) along with the dot operator(.) is known as safe navigation operator(?.). The safe navigation operator makes sure that if the variable used before the operator is not defined or java null, then instead of throwing an error, the operator returns undefined for that particular access.
If you do not define myvar, then myvar?.firstlevel returns undefined instead of throwing an error. If you accessmyvar?.firstlevel.nextlevel, then it throws an error (notice the absence of safe navigation operator before ‘nextlevel’), because myvar?.firstlevel returned undefined.
You can use safe navigation at all levels so that final result of a complete statement returns undefined even if a single element anywhere in the chain does not exist.
You can slo use safe navigation with function calls or you can combine both struct access and function calls. If you use the safe navigation operator on function calls, then any kind of error thrown from the function or if the function itself does not exist, it will be safely handled and returns undefined.
Note: You can use the safe navigation operator with Elvis operator to get the default value in case of an error as shown below:
result = myvar?.firstlevel?.nextlevel?.udf()?.trim() ?: “oops, something went wrong”;
Ordered Structs
When you iterate over a struct in ColdFusion, there is no guarantee of the order of keys. The order is random. In ColdFusion (2016 release), it is possible to maintain the order of keys in which they were inserted. It is known as insertion order.
Ordered structs allow you to maintain insertion order of the keys in a struct. There are two key differences in ordered structs and sorting of normal structs. In normal structs, you cannot get insertion order in case of sorting. But in ordered structs, you can always maintain the order since insertion of a key. If you have to insert keys, but have to access it in ordered manner multiple times, opt for ordered structs for better performance.
myStruct = structNew(“ordered”); myStruct.first = “I will always be the first one”; myStruct[“second”] = “No matter what, I am the second one”; You can also create an ordered struct using a literal syntax: myStruct = [first : “Always number one”, second = “First runner up”];
Note: In literal syntax of ordered structs, use square brackets like an array, but unlike an array, use key-value pairs.

Pass arrays by reference

In ColdFusion, by default, arrays are passed by value.  In ColdFusion 2016, users can pass arrays by reference, which greatly improves the performance of UDFs.
You can control this behavior via the application level setting:
this.passArraybyReference=true/false; (false by default)
Setting this parameter true can improve the performance up to 25 times.

Scope Lookup

By default, ColdFusion looks for an unscoped variable in all the implicit scopes (CGI, URL, FORM, Cookie, File, Client scopes, and so on). This is an expensive operation. In ColdFusion (2016 release), you can disable this implicit scope lookup programmatically and improve performance.
You can control this behavior via the application level setting:
searchImplicitScopes = true/false. (true by default)
Setting this to false can improve the performance up to five times.

Unsynchronized arrays

Until ColdFusion 11, arrays used to be thread safe.
But thread safety comes at a cost of synchronizing the array object. In a synchronized array, two or more threads cannot access the array at the same time. The second thread has to wait until the first thread completes its job, resulting in significant performance deterioration.
In ColdFusion (2016 release), you can use an unsynchronized array and let multiple threads access the same array object simultaneously.
You can use unsynchronized arrays in situations where you need not worry about multiple threads accessing the same array. In other words, if you are defining an unsynchronized array in a thread safe object, like a UDF or a CF-Closure,  you can use an unsynchronized array.
While a normal array is slower but thread safe, an unsynchronized array is faster by more than 90%.
ar_obj = arrayNew(numeric dimension, boolean isSynchronized);
When isSynchronized is false, the function an unsynchronized array. When this parameter is true or no parameter is specified, the function returns a synchronized array.