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

Faster completion #413

Merged
merged 9 commits into from
Apr 9, 2021
Merged

Conversation

renkun-ken
Copy link
Member

@renkun-ken renkun-ken commented Apr 8, 2021

Closes #412

This PR improves the performance of completion by limiting the max number of completions to return to the client and utilizing the isIncomplete feature.

If the completion list contains more than nmax (by default, 200) items, then the list is sorted by whether it starts with token and the sortText of the item, and the top nmax items are returned with isIncomplete = TRUE so that subsequent keystrokes will still trigger completion requests until the completion list is narrowed down to no greater than nmax.

This largely avoids too much traffic from the response to the completion request triggered by the first keystroke, which could potentially match too many results.

Old behavior (on my machine working in languageserver project):

  1. Type a
  2. 1619 matches returned to client with isIncomplete=FALSE, and subsequent keystrokes do not trigger completion request.

In this case, a notable delay could be observed on first keystroke of a token.

New behavior:

  1. Type a
  2. 1619 matches reduced to 200 returned to client with isIncomplete=TRUE.
  3. Type s
  4. 288 matches reduced to 200 returned to client with isIncomplete=TRUE
  5. Type .
  6. 119 matches returned to client with isIncomplete=FALSE, and subsequent keystrokes do not trigger completion request.

In this case, the traffic between server and client is reduced and the delay on first keystroke is much reduced.

@renkun-ken renkun-ken requested a review from randy3k April 8, 2021 15:12
@@ -499,10 +501,32 @@ completion_reply <- function(id, uri, workspace, document, point, capabilities)
)
}

init_count <- length(completions)
nmax <- getOption("languageserver.max_completions", 200)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this setting name should be more explicit, it gives users a feeling that this is the absolute maximum number of items.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is indeed the max number of completion items to return to the client. The results will be truncated to this number if it is more than that. Am I misunderstanding your meaning?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, you are correct. I was confused. Sorry for the noise.

R/completion.R Outdated Show resolved Hide resolved
@renkun-ken renkun-ken merged commit 2564649 into REditorSupport:master Apr 9, 2021
kar9222 pushed a commit to kar9222/languageserver that referenced this pull request Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve completion performance
2 participants