Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore request timing optimizations for typeahead search and username/tag autocompletion #3472

Closed
jywarren opened this issue Sep 25, 2018 · 5 comments
Labels
enhancement explains that the issue is to improve upon one of our existing features fto-candidate issues which are meant to be solved by first timers but aren't well-formatted yet help wanted requires help by anyone willing to contribute JavaScript

Comments

@jywarren
Copy link
Member

Our nice typeahead search is SUPER! (Thanks @milaaraujo @stefannibrasil !!)

I think we could speed it up a bit and also have it be a little less jittery by using a throttling strategy.

See how when you type the word "balloon" it makes 5 different queries?

screen shot 2018-09-25 at 2 30 33 pm

We're using Bootstrap Typeahead: https://github.com/bassjobsen/Bootstrap-3-Typeahead to run this code.

For starters, we can set the minLength and delay to 3 and 1, respectively, so it only starts searching after 3 characters are input, and only sends one request per second. This should slow things down a good bit (but test it out locally to see if it works for you!)

After merging those changes, we could explore more sophisticated "debounce" strategy -- https://davidwalsh.name/javascript-debounce-function

@jywarren jywarren added enhancement explains that the issue is to improve upon one of our existing features help wanted requires help by anyone willing to contribute JavaScript fto-candidate issues which are meant to be solved by first timers but aren't well-formatted yet labels Sep 25, 2018
@jywarren jywarren added this to the Search improvements milestone Sep 25, 2018
@daningenthron
Copy link
Contributor

Hi, I'd be interested in working on this - would you prefer to format it as an FTO first?

@jywarren
Copy link
Member Author

jywarren commented Oct 8, 2018

Hi! This may be a relatively complex one that would need to be solved in a few parts. But the basic minLength and delay to 3 and 1 could be pretty straightforward. If you'd like to give that a try and are comfortable getting started, you can go ahead, otherwise one of the GCI mentors can perhaps format it as a true guided first timers issue, which we're happy to do. Thanks!

@kevinzluo
Copy link
Collaborator

kevinzluo commented Dec 8, 2018

Hi @jywarren .
I was going to post an FTO for this and decided to test out the delay option. It feels that 1s is a bit too long since it appears to me that new searches are made delay milliseconds after the last key was pressed, so the user is forced to wait for a bit even after finishing typing. Maybe we could reduce it?

This is just pure speculation, but I searched around and found the avg typing speed is about 40 wpm and given about 5 characters per word, there will be 1 character around ~300 ms. So maybe we could set the delay to 350 ms so that it will not repeatedly search while the user is typing and won't make the user wait long after they are done?

I will go ahead and post an FTO for this 👍 . If you would like for me to make any changes, just let me know 😄 .

@jywarren
Copy link
Member Author

jywarren commented Dec 10, 2018

thanks for doing this! This is merged. I think we could continue to refine this using different strategies like the above debounce. Also perhaps looking at:

https://lodash.com/docs/4.17.10#debounce

https://css-tricks.com/debouncing-throttling-explained-examples/

https://davidwalsh.name/javascript-debounce-function

@milaaraujo @sagarpreet-chadha just a note because I think i've mentioned debounce to both of you at different points, the last link above is pretty good explanation for this strategy!

@jywarren jywarren changed the title Explore request timing optimizations for typeahead search Explore request timing optimizations for typeahead search and username/tag autocompletion Feb 5, 2019
@jywarren
Copy link
Member Author

jywarren commented Feb 5, 2019

Moving this analysis here to help explain the bottlenecks in typeahead:

image

Note how many requests go out -- i think we can change the settings on the typeahead to refine this. See a gif:

typeahead

Also note it's sending lots of requests where query is empty. We should adjust so it only sends when there are at least 2.

So we might still pursue:

  1. a debounce strategy as described above with initial attempt in initial debounced typeahead with debug statements #3172
  2. not sending requests until at least 3 characters are typed
  3. local caching of responses (see atwho docs?)

This would apply to both the typeahead search code (using Bootstrap Typeahead):

https://github.com/publiclab/plots2/blob/master/app/assets/javascripts/restful_typeahead.js

And the comment form autocompletion code (using At.js):

https://github.com/publiclab/plots2/blob/master/app/assets/javascripts/atwho_autocomplete.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement explains that the issue is to improve upon one of our existing features fto-candidate issues which are meant to be solved by first timers but aren't well-formatted yet help wanted requires help by anyone willing to contribute JavaScript
Projects
None yet
Development

No branches or pull requests

3 participants