> than that" it's not the primitive thing they're talking about their
> implementation of it: even in simple testing code can often be
> optimized.
More importantly, though, most of the "which is faster" stuff is
practically useless. If you're concerned about performance, focus on
database usage and caching, the two biggest areas of potential
optimization for every web application I've ever seen. Lists may be
faster than arrays, or slower, but the difference in your production
applications will be negligible. In addition, things like this change
over time - in one version of CF, one may be faster than the other,
while in another the reverse may be true. I strongly recommend just
using the data structure that seems most sensible for a particular use,
rather than worrying about optimization at that level.
> Secondly when CF loops over a list the list is tokenized (from what
> I've been told just once). However when somebody loops over an Array
> they often loop to "ArrayLen()" - this function is then run for EACH
> iteration (you can see this by looping over a large, session-based
> array while adding elements in another thread - the first page will
> loop to the new length, not the old one). This slows things down.
> Using a proxy variable can eliminate that lag, of course.
This is not true. The attribute values within a CFLOOP tag are not
reevaluated for every iteration of the loop. They are evaluated once,
before the loop starts. This is true in CFMX, and was true in CF 5 last
time I checked. The code below demonstrates this.
<cfset aStooges = ArrayNew(1)>
<cfset aStooges[1] = "Moe">
<cfset aStooges[2] = "Larry">
<cfset aStooges[3] = "Curly">
<cfloop index="i" from="1" to="#ArrayLen(aStooges)#">
<cfif i is 1>
<cfset aStooges[4] = "Shemp">
</cfif>
<cfoutput>#aStooges[i]#</cfoutput>
</cfloop>
<cfdump var="#aStooges#">
> Thirdly, and this is where things get really fuzzy for me, if what
> I've been told is correct and the list is only tokenized once when
> looping over it, where is that tokenization stored? My guess is that
> it's stored in a primitive array. If I'm correct (and it's only a
> guess) then looping over a list is, in reality, doing (in a way) a very
> low-level conversion of the list to an array then looping. So it may
> that the reason that looping over a list is so fast is because looping
> over an array is so fast!
It may be, or may not be, but it's folly to take this approach to
figuring out how CF works. Without exact knowledge about the
interpretation process in CF 5 or of the bytecode compilation process in
CFMX, we simply don't have enough information to do more than guess.
Those sorts of implementation details are abstracted away from the CF
developer for a very good reason. They may change in future versions of
CF.
> CF Arrays aren't Java Arrays. They're counted from 1, not zero.
> They're passed by value not by reference (which I wish would change).
Well, CF isn't Java. Some languages treat arrays as first-class objects,
while others don't. It would be a bad idea to change this now, with all
the existing CF code in the world.
Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
phone: 202-797-5496
fax: 202-797-5444
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

