Reduce debounce to make search about 2x faster #2407
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On docs.julialang.com, the time between pressing typing the final character of the search query and seeing search results is about 457ms (N=1). 300ms of that is waiting for the debounce to decide the user is done typing and start the search process. After this PR, the total delay drops to 249ms (N=1). I measured delay by taking a slow motion video of my fingers on the keyboard and the display on the screen so this is an "all inclusive" timing. On docs.julialang.org this speeds up searches by 1.8x, and on smaller search domains (e.g. most packages) the speedup may be a bit larger, approaching 3x.
This should not result in overwhelming the browser on fast typing. Faster than 10 chars/s will simply wait for the final character and then 100 more ms. Slower than 10 chars/s the search should be able to handle.
It is possible to do much more intelligent/clever debouncing that, for example, dynamically adjusts the debouncing delay based on observed typing speed and observed search runtime. That seems like an interesting project to pursue, but for now, this PR is quite simple and gives substantial performance gains.
I also switched keyup to keydown to shave a few extra milliseconds off the latency. Once a user presses a key down in the search bar, they are committed to performing a search for the new term, so we might as well start the clock a bit earlier.