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 developer advocate for HERE Technologies. He focuses on JavaScript, serverless 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