Using ColdFusion's Autosuggest? Check your query size

This post is more than 2 years old.

Here's an interesting issue I ran into tonight while reviewing some code from a friend. He had a complex search form that included multiple uses of ColdFusion's autosuggest feature. If you haven't seen this yet, it is a feature of the cfinput tag that makes it pretty easy to build an autosuggest field. You can point the tag to a CFC, return an array of data, and it gets rendered as a set of suggestions to the user.

While testing, I had Chrome Dev Tools turned on. I noticed the network call to the CFC was returning nearly 200k of data! That's quite a bit. I right clicked into Chrome Dev Tools and got the full URL of the Ajax call. I pasted this into a new tab and saw why the size was so big. There was a huge amount of data.

Here's where things got interesting though. On the front end, only 10 results were displayed. I turned to the docs and found that one of the attributes for cfinput is maxResultsDisplayed. This is optional. Can you guess what it defaults to? 10. That's a perfectly reasonable result, but what it also means is that it is easy to miss a performance issue where your sending huge amounts of data over the wire but only rendering a small amount.

The fix is easy - just limit the results in your CFC. Problem solved. But again - because the front end limits what you see - you may miss the fact that you're shuttling back a lot of data.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Rich Hefter posted on 9/5/2012 at 6:05 PM

Hi Ray,
A few years ago, I had asked you the same question in your CF forum. I was having terrile performance on a cascading dropdown using the BIF of CF. The 2nd dropdown yeided about 1,000 entries. You told me basically the same thing.
Oddly enough, when I tried a server side solution (not AJAX), the page with the 1,000 entries loaded quite quickly.

I'm not an JQuery expert but this seemed to make sense to you at the time.

hefterr

Comment 2 by Raymond Camden posted on 9/5/2012 at 6:08 PM

Wow, I've forgotten quite a bit I think. ;)

Comment 3 by Rich Hefter posted on 9/5/2012 at 6:17 PM
Comment 4 by David Knighton posted on 9/5/2012 at 8:55 PM

I witnessed this very problem with an HR-related project last year. Confounded the bejeezus out of me. What a simple fix after all that hair-pulling.