Migrate search suggestions to use the streaming API
Created by: lguychard
Why does this matter?
Our suggestions API has always returned repositories, paths and symbols. But fetching dynamic suggestions is slow, whereas static suggestions (such as filter names) are always displayed immediately. Since we do not show a loading indicator hinting that dynamic suggestions are loading (because we don’t know whether any dynamic suggestions are actually going to be returned), most users probably never see dynamic suggestions when typing any random pattern.
Yet, these dynamic suggestions can be very useful: for instance they allow you to add a valid repo:
filter for the facebook/react repository by just typing facebook
in the search input: https://sourcegraph.slack.com/archives/C020S8AT3LN/p1631634298111200
Why are these suggestions so slow (for a global search, they usually take 3 seconds)?
Suggestions use the “old” GraphQL API and every time we increase our corpus we get a slower “time to LAST result”. Unfortunately we wait for all suggestions to return or hit a timeout at 3s. On Cloud this effectively means a user has to wait 3s, because often at least one the suggestions won’t finish in time. Recent work on suggestions improved suggestions for symbols because we can now skip repo resolution which makes a lot of symbol searches return quicker than 3 seconds. However this does not impact the other suggestion types.
What's the fix?
The only permanent fix is to migrate suggestions to the stream API:
- Instead of
graphql?SearchSuggestions
, call/stream
directly - The
SearchSuggestions
GraphQL endpoint can be marked for deprecation (then we can simply delete the code at a later point in time). The impact is minimal, as this endpoint is simply useful for internal consumption.
An opportunity to improve suggestions
With suggestions switching to just being raw search queries made from the client, we could use some simple heuristics to make them really snappy + relevant, for instance (just some raw ideas):
- While query being typed is just a literal pattern, get just repo suggestions using
r:$PATTERN
- As soon as a query is scoped down with a
repo:
filter, get just symbol and path suggestions - ...
It also opens up the opportunity for really improving the UX of search suggestions (again just some raw ideas):
- When typing
facebook react
, get suggestions forr:facebook.*react
- Make suggestions aware of search expressions, to get really snappy suggestions in individual expression branches
- ...