0

I'm implementing some ajax autocomplete. Whenever user types something result gets displayed. One thing that is bad about those autocomplete is that constantly hitting database.

So I went with making some timeout to decide if user stopped typing.

So here is the question, what would you suggested for timeout? Currently I have half of the second.

  • I'm confused when you say "always hitting the database." There are multiple ways to look for user interactions without a timer. Is there something in your situation that demands a timer? – Evil Closet Monkey Mar 29 '14 at 16:41
0

I would suggest another approach. Instead of hitting the database every single keystroke or after a particular interval, why not hit the database one time on page load, pull down your dataset of possibilities, and filter off of that? Doing that would be nearly instantaneous.


It's a few years old, but this article may be of interest to you as well:

Building Fast Client-side Searches

Here is a small excerpt:

There was one optimization we made to our AutoComplete configuration that was particularly effective. Regardless of how much we optimized our search method, we could never get results to return in less than 200ms (even for trivially small numbers of contacts). After a lot of profiling and hair pulling, we found the queryDelay setting. This is set to 200ms by default, and artificially delays every search in order to reduce UI flicker for quick typists. After setting that to 0, we found our search times improved dramatically.

  • this is interesting, since my markup would allow this but not sure about memory since I can have about million such things that should be filtered. (current problem) but still will not accept as anwer since I still interested in others opinions. I have different places when using such approach such as searching youtube videos. – CBeTJlu4ok Mar 28 '14 at 19:22
  • @Mpa4Hu - A million things may sound like a lot, but the only way to know for sure is to simply test it. – Code Maverick Mar 28 '14 at 19:28
  • A million things may sound like a lot, but it is a lot! With average word length in English being 5.1 chars a million words would roughly be 4.86MB. Fetching that much extra for a page load is unjustified. Take into account how many people might be on a slow connection or using mobile devices with limited data plans. – uKolka Sep 3 '14 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.