ColdFusion Implicit Struct Creation Oddness

Totally unexpected behavior, possibly showing some insight into how the Adobe's implementation of implicit struct creation works behind the scenes. I'd be curious to see if this different in Railo1

<cfscript>
wsConfig = {
 root = "https://example.com/baaws/",
 corews = wsConfig.root & "core/ws?wsdl",
 utilws = wsConfig.root & "core/wsutil?wsdl",
 dispatcherws = wsConfig.root & "dispatcher/ws?wsdl",
 emailexchangews = wsConfig.root & "emailexchange/ws?wsdl",
 emaildominows = wsConfig.root & "emaildomino/ws?wsdl",
 emailgroupwisews = wsConfig.root & "emailgroupwise/ws?wsdl"
};
</cfscript>

You're able to reference a member of the wsConfig struct before the struct is even created! At least before I'd expect it to be created. To accomplish the same thing (avoid using temporary variables to create the object, but define my root URL for reuse) in PHP (without using unset()) I'd do something like:

<?php
$wsConfig = array(
 root => 'https://example.com/baaws/',
);
 
$wsConfig = array(
 root => $wsConfig['root'],
 corews => $wsConfig['root'] . 'core/ws?wsdl',
 utilws => $wsConfig['root'] . 'core/wsutil?wsdl',
 dispatcherws => $wsConfig['root'] . 'dispatcher/ws?wsdl',
 emailexchangews => $wsConfig['root'] . 'emailexchange/ws?wsdl',
 emaildominows => $wsConfig['root'] . 'emaildomino/ws?wsdl',
 emailgroupwisews => $wsConfig['root'] . 'emailgroupwise/ws?wsdl',
);
?>

In this case the second time I reference $wsConfig I'm using the values from the first copy. The first copy isn't destroyed until after the second copy is set.

Performance Impact

The first question I have is if there is any performance impact to creating a large struct implicitly versus using a Java object. In Adobe ColdFusion it seems the largest struct you can implicitly create outside of a function is one with 16319 members. Inside of a function the limit appears to be 3451 members.

Build yourself a testcase using the following code, or download a pre-assembled testcase:

<cfsetting enablecfoutputonly="yes" showdebugoutput="no">
<cfscript>
writeoutput("&lt;cfscript&gt;<br />struct = {<br />");
for( x = 1; x LT 16319; x = x+1 ) {
	writeoutput("abc#x# = 'abc#x#',<br />" );
}
x = x+1;
writeoutput("abc#x# = 'abc#x#'<br />" );
writeoutput("};<br />&lt;/cfscript&gt;");
</cfscript>

I'm not sure if you can use Java to implicitly create a struct (coldfusion.runtime.Struct in Adobe CF) or implicitly create a java.lang.object. Implicit creation of a large struct is much faster than creating a struct repeatedly calling StructInsert() (download testcase).

  1. OpenBD doesn't support implicit creation yet. [back]

 

Tags: ,

Leave a Reply


© 2007-2012, Corey Gilmore | Posts RSS Feed | Comments RSS Feed | Contact

 

The views expressed on these pages are mine alone and not those of any past or present employer. All information presented on this site was obtained lawfully and not through disclosure under the terms of an NDA.