Recent Entries
- MangoBlog/Oracle Int...
- OT - Google Maps: In...
- Email Hijacked?
- CFUnited: Refactorin...
- CFUnited: Continuous...
- CFUnited: Prototypin...
- CFUnited: All about ...
- CFUnited: Event Driv...
- CFUnited: Integrated...
- CFUnited: ColdBox Fr...
Popular Entries
- CFUnited: All about ...
- SAML and ColdFusion ...
- SAML and ColdFusion ...
- SAML and ColdFusion ...
- SAML and ColdFusion ...
- SAML and ColdFusion ...
- Import/Export in SQL...
- CFUnited: Google Web...
- Second Blog CFC Surv...
- Improving Performanc...
Top Commenters
- Nathan Mische (12)
- CFFusionDev (6)
- CFdevfusion (6)
- Peter Bell (4)
- Sean Corfield (3)
- Rey Bango (3)
- Terrence Ryan (3)
- ah7866 (3)
- Scott (2)
- Jim Priest (2)
Slideshows
Dresser/Changing Table...Images related to the lay...
Nursery renovations...
Pool Surprises...
Sponsored Links
Search
Subscribe
Enter your email address to subscribe to this blog.RSS
Tags
cfug cfunited coldfusion flex generalArchives
- Adobe (5) [RSS]
- AIR (6) [RSS]
- ASP.NET (2) [RSS]
- BlazeDS (1) [RSS]
- Books (1) [RSS]
- CFEclipse (5) [RSS]
- CFML (0) [RSS]
- CFUG (26) [RSS]
- CFUnited (23) [RSS]
- ColdFusion (53) [RSS]
- College Football (3) [RSS]
- Conferences (1) [RSS]
- Development Tools (3) [RSS]
- DIY (1) [RSS]
- Eagles (3) [RSS]
- Fireworks (1) [RSS]
- Flash (3) [RSS]
- Flex (10) [RSS]
- Flyers (2) [RSS]
- Frameworks (5) [RSS]
- General (28) [RSS]
- Hockey (2) [RSS]
- Hosting (1) [RSS]
- House (2) [RSS]
- HTML (2) [RSS]
- JavaScript (1) [RSS]
- Jobs (1) [RSS]
- Macromedia (0) [RSS]
- MangoBlog (1) [RSS]
- Misc. (5) [RSS]
- Model-Glue (4) [RSS]
- Navy Football (5) [RSS]
- onair2007Philadelphia (3) [RSS]
- onairbustour (3) [RSS]
- Open Source (0) [RSS]
- Other (2) [RSS]
- Other Sports (4) [RSS]
- Performance (3) [RSS]
- Personal (2) [RSS]
- Phillies (2) [RSS]
- Projects, User Group Manager (1) [RSS]
- Rant (1) [RSS]
- Rants (1) [RSS]
- SAML (6) [RSS]
- Site (1) [RSS]
- Soccer (4) [RSS]
- SQL Server (2) [RSS]
- Transportation (1) [RSS]
- Wedding (2) [RSS]
AGGREGATORS
Improving Performance: Using Structures instead of Arrays
Posted On November 21, 2006 4:54 PM By Phil in ColdFusion,Performance
In this entry on performance, I want to talk about using Structures to help save performance. I believe Structures are probably one of the least utilized variable types in the CF Community, yet they are probably the most powerful. At work, in some of the reports I was looking at improving, they utilized a base query (which I talked about in earlier posts) but had supporting, aggregate-based queries. To add the SQL in these queries would critically drop the performance of the report.
In this report, in addition to all the meetings and presentations a member may have attended, we also want the first attended meeting to be displayed. The query for this would be something like:
<CFQUERY name="qryFirstmeeting" dbtype="query">
SELECT userId, min(meetingDate) as firstMeeting
FROM qryMeetings
GROUP BY userId
ORDER BY userId
</CFQUERY>
Now, I have seen some developers do this in every loop of the CFOUTPUT tag, but that contributes to the performance issues one may see on the report/display of this data. At, the reports I was evaluating had something along the following:
SELECT userId, min(meetingDate) as firstMeeting
FROM qryMeetings
GROUP BY userId
ORDER BY userId
</CFQUERY>
<CFSET arrFirstMeeting = ArrayNew(1) />
<CFOUTPUT query="qryFirstMeeting">
<CFSET arrFirstMeeting[qryFirstMeeting.userId] = qryFirstMeeting.firstMeeting />
</CFOUTPUT>
<!-- In the report code -->
<CFOUTPUT query="qryMeetings">
<!-- other elements -->
<TD>#DateFormat(arrFirstMeeting[qryMeetings.userId])#</TD>
<!-- Rest of output -->
</CFOUTPUT>
Now, this code is ok if your userIds start at 1 and there are no breaks, but with data zero downs, deleting of profiles, etc., we know this isn't the case. If, for instance, the userIds started at 100, then the very first <CFOUTPUT query="qryFirstMeeting">
<CFSET arrFirstMeeting[qryFirstMeeting.userId] = qryFirstMeeting.firstMeeting />
</CFOUTPUT>
<!-- In the report code -->
<CFOUTPUT query="qryMeetings">
<!-- other elements -->
<TD>#DateFormat(arrFirstMeeting[qryMeetings.userId])#</TD>
<!-- Rest of output -->
</CFOUTPUT>
<CFSET stctFirstMeeting = StructNew() />
<CFOUTPUT query="qryFirstMeeting">
<CFSET StructInsert(stctFirstMeeting,"#qryFirstMeeting.meetingId#","#qryFirstMeeting.firstMeeting#") />
</CFOUTPUT>
<!-- In the report code -->
<CFOUTPUT query="qryMeetings">
<!-- other elements -->
<TD>#DateFormat(stctFirstMeeting["#qryMeetings.userId#"])#</TD>
<!-- Rest of output -->
</CFOUTPUT>
Now, in this instance, ColdFusion does not have to fill in any array elements and the number of keys is equal to the recordcount and the lookup is cleaner. The above technique along with the previous two posts helped to dramatically improve performance in a number of areas of our systems and hope the examples, while simple, show the techniques in a clear manner.
<CFOUTPUT query="qryFirstMeeting">
<CFSET StructInsert(stctFirstMeeting,"#qryFirstMeeting.meetingId#","#qryFirstMeeting.firstMeeting#") />
</CFOUTPUT>
<!-- In the report code -->
<CFOUTPUT query="qryMeetings">
<!-- other elements -->
<TD>#DateFormat(stctFirstMeeting["#qryMeetings.userId#"])#</TD>
<!-- Rest of output -->
</CFOUTPUT>


philduba.com




Comments