Skip to main content
Inspiring
May 9, 2006
Answered

Array bottleneck...need assistance

OK, I have a bit of code that is BOGGING down my app. I need some ideas for smoothing it out. Basically, I need to be able to reference an array by 3 elements (id, qstn_id, zone_id). In a query later, I sum up the data and assign it to the proper position in the array (ie zone1[6552][124747][16543] = 2). When you create an array, does it create all of the elements below the element I have created? For the example above, does CF have to create positions for 1-6551 for the first element, 1-124746 for the second, etc? Would it help any to reference the position in the original reference list rather than the actual IDs? Ex. instead of zone1[6552][124747][16543], it would be zone1[1][1][1].

I'm not married to the idea of the array. My other idea was to assign dynamic variables to the zones, but I don't think it would help.

Any help/ideas will be appreciated.
This topic is closed to new replies. Start a new post to keep the conversation going.
DongerNeedFoodCorrect answer
Inspiring
May 10, 2006
I tried a couple of solutions:

First, I made the array positions be the list index values instead of the actual ID.

So instead of: cfset xrayzones1[ i ][ q ][ z ] = 0

I used: cfset xrayzones1[listfind(id_lst,i)][listfind(qstn_list,q)][listfind(zone_list,z)] = 0

This solution improved processing time dramatically and decreased mem usage. But I wanted to see if structures would improve it more.

My second attempt involved using structures to declare my zones. Ultimately, I went with structures because it produced the fastest processing time. My processing time went from ~8seconds to 0.35seconds. Here's the code:

5 replies

Inspiring
May 9, 2006
Could you get by with a 2 dimensional array and you only need to declare it once:

<cfset YourArray = ArrayNew(2)>

<CFSET YourArray[index][1] = id_list>
<CFSET YourArray[index][2] = qstn_list>
<CFSET YourArray[index][3] = zone_list>

Additionally, You may want to consider researching structures for this
Translate
Participant
May 9, 2006
You are creating a giant empty array, which is why performance is so slow. Keep in mind that CFMX code turns into Java code, and your CF array becomes Vector object in Java.

Have you considered using a structure instead? Then you could use your IDs as keys and avoid the overhead of creating a big empty array for which Java has to allocate and deallocate memory.
Translate
DongerNeedFoodAuthorCorrect answer
Inspiring
May 10, 2006
I tried a couple of solutions:

First, I made the array positions be the list index values instead of the actual ID.

So instead of: cfset xrayzones1[ i ][ q ][ z ] = 0

I used: cfset xrayzones1[listfind(id_lst,i)][listfind(qstn_list,q)][listfind(zone_list,z)] = 0

This solution improved processing time dramatically and decreased mem usage. But I wanted to see if structures would improve it more.

My second attempt involved using structures to declare my zones. Ultimately, I went with structures because it produced the fastest processing time. My processing time went from ~8seconds to 0.35seconds. Here's the code:
Translate
Inspiring
May 9, 2006
Also, I just ran this little bit of code, along with the query to assign the values to the array. It ran in about 8 seconds, but I watched the Memory Usage for jrun.exe spike from 61MB to 385MB in that time. Do arrays really have this affect? Or are my array limits just too big? It's also been about 5 minutes and my mem usage has only gone down to 135MB. I'm using MX7 on my test server, so I'm the only one on it.
Translate