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!
cafosterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agx_Commented:
> Unless I've missed something (which is always highly possible), the only way
> 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.
_agx_Commented:
I ran a few tests, using a sample query of 5 columns,  8-10K records, and different ordering.  With my very simple output, there's definitely a performance difference between grouped/non-grouped.  These are some of the times below. The overall time isn't bad. But on average, you can definitely see a difference.


(8k records)
grouped/non-grouped  in ms.
===============
125/31
172/141
47/31
140/94
109/62

(10k records)
grouped/non-grouped  in ms.
===============
219/47
219/187
141/46

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cafosterAuthor Commented:
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!
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

_agx_Commented:
> 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 ;-)  
cafosterAuthor Commented:
True... thanks for your help!
_agx_Commented:
Welcome :)
_agx_Commented:
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="otherCfoutputCode.cfm">
       </cfoutput>
<cfelse>
       <cfoutput query="queryName">
               <cfinclude template="otherCfoutputCode.cfm">
       </cfoutput>
</cfif>
_agx_Commented:
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>

Open in new window

cafosterAuthor Commented:
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 :-)
_agx_Commented:
Glad I could I help :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.