-
Notifications
You must be signed in to change notification settings - Fork 451
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
fix: auto-completion bugs and performance #3460
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mhuisi
force-pushed
the
mhuisi/slow-autocompletion
branch
from
February 22, 2024 20:27
7dbd52e
to
a565aa7
Compare
github-actions
bot
added
the
toolchain-available
A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
label
Feb 22, 2024
Mathlib CI status (docs):
|
Kha
reviewed
Feb 23, 2024
Kha
approved these changes
Feb 23, 2024
mhuisi
force-pushed
the
mhuisi/slow-autocompletion
branch
from
February 26, 2024 09:21
4f7839a
to
5c2ef8a
Compare
mhuisi
added a commit
to mhuisi/lean4
that referenced
this pull request
Feb 28, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
toolchain-available
A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
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.
This PR addresses several performance issues in the auto-completion implementation. It also fixes a number of smaller bugs related to auto-completion.
In a file with
import Mathlib
, the performance of various kinds of completions has improved as follows:C
: 49000ms -> 1400msCat
: 14300ms -> 1000msx.
forx : Nat
: 3700ms -> 220ms.
for an expected type ofNat
: 11000ms -> 180msThe following bugs have been fixed as well:
.<identifier>
(where the expected type is used to infer the namespace) did not filter by the expected type and instead displayed all matching constants in the respective namespace. Now, it uses the expected type for filtering. Note that this is not perfect because sub-namespaces are technically correct completions as well (e.g..Foo.foobar
). Implementing this is future work..
was often not possible at all. Now, as long as the.
is not used in a bracket (where it may be used for the anonymous lambda feature, e.g.(. + 1)
), it triggers the correct completion.#check
commands would always try to complete identifiers using the full declaration name (including namespaces) if it could be resolved. Now it simply uses the identifier itself in case users want to complete this identifier to another identifier.Details
Regarding completion performance, I have more ideas on how to improve it further in the future.
Other changes:
The following approaches have been used to improve performance:
completionItem/resolve
requests to compute the type lazily when the user selects a completion item.LSP's solution for this dilemma is to have servers send all the state they need to compute a response to a resolve request to the client as part of the initial auto completion response (which then sends it back as part of the resolve request), but this is clearly infeasible for all real language servers where the amount of state needed to resolve a request is massive.
This means that the only practical solution is to use the current state to compute a response to the resolve request, which may yield an incorrect result. This scenario can especially occur when using LiveShare where the document is edited by another person while cycling through available completions.
This PR also adds a couple of regression tests for fixed bugs, but no benchmarks. We will add these in the future when we add proper support for benchmarking server interaction sessions to our benchmarking architecture.
All tests that were broken by producing different completion output (empty
detail
field, addedsortText?
anddata?
fields) have been manually checked by me to be still correct before replacing their expected output.