cafoster
asked on
performance with cfoutput grouping
I've built a search form in ColdFusion 8 which allowing users to choose whether or not they want the results grouped by record type. If they choose yes, then I display the returned data within a cfoutput tag using the "group" attribute:
<cfoutput query="queryName" group="recordType">
For code efficiency, I would like to use the same <cfoutput> tag, whether or not the results are grouped. I cannot leave the group attribute empty, and I haven't found the logic that would allow me to alter or repeat only the opening <cfoutput> tag, including the group attribute in one and not in the other.
Unless I've missed something (which is always highly possible), the only way to avoid repeating the entire <cfoutput> tag (about 100 lines of code), grouping data in one and not in the other, would be to use the group attribute regardless of the user's selection. I could do this, since each row in either result set contains a unique ID value. I would set the default value for a "groupBy" variable to "uniqueID" and overwrite it with "recordType" when a user wants to group the data.
My question ... would I be taking a significant performance hit by doing this? There'd essentially be one row per group, and I don't know if ColdFusion processing involved would impact performance. The data set would have about 10 columns and could be as large as 8,000 records.
Thoughts?
Thanks!
<cfoutput query="queryName" group="recordType">
For code efficiency, I would like to use the same <cfoutput> tag, whether or not the results are grouped. I cannot leave the group attribute empty, and I haven't found the logic that would allow me to alter or repeat only the opening <cfoutput> tag, including the group attribute in one and not in the other.
Unless I've missed something (which is always highly possible), the only way to avoid repeating the entire <cfoutput> tag (about 100 lines of code), grouping data in one and not in the other, would be to use the group attribute regardless of the user's selection. I could do this, since each row in either result set contains a unique ID value. I would set the default value for a "groupBy" variable to "uniqueID" and overwrite it with "recordType" when a user wants to group the data.
My question ... would I be taking a significant performance hit by doing this? There'd essentially be one row per group, and I don't know if ColdFusion processing involved would impact performance. The data set would have about 10 columns and could be as large as 8,000 records.
Thoughts?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wow, I expected a hit, but extrapolate that across a larger result set and your looking at a dog of a page to load. Looks like I'll be duplicating code on this one, much as it pains the efficiency expert in me ;-)
Thanks!
Thanks!
> much as it pains the efficiency expert in me ;-)
Me too .. Just for grins, try it with your code base first. If it's just a difference of 50-100ms in your app, it might be something you could live with ;-)
Me too .. Just for grins, try it with your code base first. If it's just a difference of 50-100ms in your app, it might be something you could live with ;-)
ASKER
True... thanks for your help!
Welcome :)
One more thing. Did you look into cfincludes? They _might_ work here. The main output ie 100 lines could be moved to a separate template. Then called within a cfif.
<cfif isGrouping>
<cfoutput query="queryName" group="someCol">
... do stuff here ...
<cfinclude template="otherCfoutputCod e.cfm">
</cfoutput>
<cfelse>
<cfoutput query="queryName">
<cfinclude template="otherCfoutputCod e.cfm">
</cfoutput>
</cfif>
<cfif isGrouping>
<cfoutput query="queryName" group="someCol">
... do stuff here ...
<cfinclude template="otherCfoutputCod
</cfoutput>
<cfelse>
<cfoutput query="queryName">
<cfinclude template="otherCfoutputCod
</cfoutput>
</cfif>
Correction:
<cfif isGrouping>
<cfoutput query="queryName" group="someCol">
... do stuff here ...
<cfoutput>
<cfinclude template="otherCfoutputCode.cfm">
</cfoutput>
</cfoutput>
<cfelse>
<cfoutput query="queryName">
<cfinclude template="otherCfoutputCode.cfm">
</cfoutput>
</cfif>
ASKER
That's the ticket! In fact, I used that approach successfully on another project long ago, but in this case I was so focused on solving the problem a certain way that using <cfinclude> didn't even occur to me. Darn tunnel vision! Thanks for the fresh perspective and for not giving up on the problem, no wonder you're ranked a Genius :-)
Glad I could I help :)
> to avoid repeating the entire <cfoutput> tag
That would be my approach too.
Honestly, I don't know. I would guess there is a performance hit for using "group". Simply because it's an extra step. How large a hit, really depends on how CF implements it (I don't know the answer). However, my guess would be that it's small. At least with a single group on a small value like a number. It could be as simple as comparing the ID in the current row with the previous one, and storing a row number.
That said, the only way to really know for sure is to test it. 8000 records is a lot to display. So a few crude benchmark test would give you a more accurate picture of whether it's and issue or not.