Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Implement Tokio-based LSP client (for testing) #1223

Merged
merged 3 commits into from
Jan 14, 2019

Conversation

Xanewok
Copy link
Member

@Xanewok Xanewok commented Jan 3, 2019

Based on #1210.

The original motivation for this work was to tackle the recent spurious failures and make sure there are no timing/racing issues, at least on the testing harness side for rls spawning integration tests, so this is an attempt that does not spawn a thread and without explicit sleeping, but instead runs on the current thread (Tokio runtime), uses async I/O to read the messages and can block the current thread until specified message arrives.

Thanks to RLS lib being exposed, this also can send typed requests; due to notification model we block on the response and return it as part of the request function call (so it's an actual RPC) and we can naturally add timeouts per each message.

At first I wanted to only work with mio instead but I found myself trying to write a lot of scaffolding that's been already implemented as parts of Tokio and mio-named-pipes, so I figured I'll pull in Tokio instead (many of the transient tokio-* deps aren't needed, there's work going at tokio-rs/tokio#808 to make these optional).

I'd say this was a good excuse to finally look at the async (ecosystem) in Rust! Given enough polish maybe it'd make sense to extract the async LSP client into separate crate?

@alexheretic @nrc I'd very much appreciate taking a look at it!

Also a shout out to @alexcrichton for mio-named-pipes and tokio-process, which made this use-case a breeze 😁

EDIT: Ported only a single test, can rewrite rest of this as a part of this PR or later if looks good enough.

@Xanewok Xanewok force-pushed the lsp-client-lib-rebase branch 3 times, most recently from 96085ac to c339b73 Compare January 8, 2019 10:34
@alexheretic
Copy link
Member

Cool! Though to be fair using an extra thread to manage stdio was never a big deal, considering we're starting up a whole RLS process.

It's a good place to start pushing in tokio style async code though.

@Xanewok Xanewok force-pushed the lsp-client-lib-rebase branch from c339b73 to 9148b8a Compare January 9, 2019 12:59
@nrc nrc merged commit 9b757c0 into rust-lang:master Jan 14, 2019
@Xanewok Xanewok deleted the lsp-client-lib-rebase branch January 20, 2019 19:18
bors added a commit that referenced this pull request Jan 22, 2019
Translate cmd tests to use async LSP client

This translates our cmd-based tests to use the LSP client introduced in #1223.

Some anecdotal benchmarks (Xubuntu 18.04, Ryzen 2600) before and after translating:
```
$ time cargo test cmd_
real    0m3,498s
user    0m8,379s
sys     0m2,710s

$ time cargo test cmd_ --release
real    0m3,059s
user    0m5,585s
sys     0m2,512s

$ time cargo test client_
real    0m3,465s
user    0m7,197s
sys     0m1,926s

$ time cargo test client_ --release
real    0m3,053s
user    0m4,977s
sys     0m1,825s
```
It seems that synchronization overhead caused by running multiple RLS and rustc instances in-process still outweighs spawning separate processes per test 🎉 That means we don't lose performance (and actually benefit) from switching over.

I plan on translating the remaining tests in tests_old as a separate PR.

r? @alexheretic
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants