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

x/tools/gopls: use BFS instead of DFS for deep completions #39113

Closed
stamblerre opened this issue May 16, 2020 · 2 comments
Closed

x/tools/gopls: use BFS instead of DFS for deep completions #39113

stamblerre opened this issue May 16, 2020 · 2 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@stamblerre
Copy link
Contributor

I suspect that using a breadth-first traversal for deep completions will lead to improvements in the speed with which deep completions finds matching candidates.

I also think this change may allow us to restructure the completions code in way that is a bit clearer by giving completions more defined "phases":

  1. collecting candidates
  2. checking if the candidates are matches and scoring
  3. formatting the matches into completion items

These phases are already exist in the code, but the fact that the deep completions happen in (*completer).found muddies the waters a bit.

Somewhat related: We could have the 100ms deep completion timeout apply to phases 1 and 2, always (even without deep completions), with no time limit on 3 to avoid dropping matches that we ran out of time to format.

@muirdm: What do you think? I haven't actually tried implementing any of this, so I'm sure I'm missing a lot, but does this sound reasonable / doable?

@stamblerre stamblerre added this to the gopls/v0.5.0 milestone May 16, 2020
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels May 16, 2020
@muirdm
Copy link

muirdm commented May 17, 2020

I agree breadth first search will typically find the good candidates sooner, so it will give better results when don't have enough time to search all the candidates.

  1. collecting candidates
  2. checking if the candidates are matches and scoring

There are cases with a lot of deep candidates (e.g. 100k), so it is important to be able to filter weak candidates as you go. You don't want to end up collecting 100k candidates, sorting and taking the top N since that will be slow. Currently we track the top N=3 deep candidate scores we have seen, and if we find a new candidate not in the top N then we don't collect it.

We could have the 100ms deep completion timeout apply to phases 1 and 2, always (even without deep completions), with no time limit on 3 to avoid dropping matches that we ran out of time to format.

My original intention was to have the 100ms budget apply to everything as you suggest, but OTOH it would be weird to miss an "obvious" lexical candidate because gopls ran out of budget for whatever reason.

Currently the item formatting can be quite slow due to documentation fetching and type/alias formatting. I don't think we should exclude the time spent formatting until we speed those up.

@stamblerre stamblerre removed this from the gopls/v0.5.0 milestone Jun 24, 2020
@dandua98 dandua98 self-assigned this Sep 12, 2020
@dandua98
Copy link

Closed by d148ae1

@golang golang locked and limited conversation to collaborators Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants