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

Optimization: Cancel pending futures on new LSP requests. #3525

Closed
JoshuaBatty opened this issue Dec 6, 2022 · 4 comments
Closed

Optimization: Cancel pending futures on new LSP requests. #3525

JoshuaBatty opened this issue Dec 6, 2022 · 4 comments
Assignees

Comments

@JoshuaBatty
Copy link
Member

The language server should cancel any pending futures that have yet to yield a result if a new request comes in from the client. For example, on every did_change event, we should stop compilation and start again immediately.

As this event happens on every keystroke, this optimization in itself should lead to a drastic speed improvement.

@JoshuaBatty JoshuaBatty changed the title LSP Optimization: Cancel pending futures on new requests. Optimization: Cancel pending futures on new LSP requests. Dec 6, 2022
@JoshuaBatty JoshuaBatty self-assigned this Dec 6, 2022
@JoshuaBatty
Copy link
Member Author

This definitely isn't a trivial thing to implement. Ideally, we would be able to take advantage of the cancelRequest part of the LSP spec to drop any current work. Unfortunately, parse_project is getting triggered by didOpen which is a notification and not an LSP request. It looks like rust-analyzer also bumped into this problem with notifications, see 666 and 584

There is also a really good discussion here where tower-lsp is considering ditching concurrent execution and also notes the same issues above.

@JoshuaBatty
Copy link
Member Author

Here you can see just how backed up the server can get in it's current state.

Screen.Recording.2023-04-10.at.11.17.00.am.mov

@JoshuaBatty
Copy link
Member Author

A good stress test for this is to rename the Option type from within sway-lib-std/src/option.sw. In doing so, the client sends out a didChange notification for each of the files that are impacted, so roughly 10 notifications one after the other.

If we implement this correctly, each subsequent didChange notification will cancel any current work done in parse_project until the final one comes in, allowing us to complete parsing of the project and be ready to receive new requests from the Client.

@JoshuaBatty
Copy link
Member Author

This was mostly addressed in #5429

We can now bail out of compilation if a newer did_change notification message is received

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant