-
Notifications
You must be signed in to change notification settings - Fork 253
RLS should compile in a separate process #1307
Description
RLS currently calls into the compiler within it's own process. As I understand it this is done to allow compiling using Vfs, or more plainly compiling a project with unsaved files.
Problems with in-process
There are, however, some drawbacks to in-process compilation. I can think of 3 good ones: static memory isolation, cancellation & stdout isolation
-
Cargo/rustc have been designed as batch tasks run from cli, whereas RLS is a long-lived process. This means static memory usage in the compiler continues to consume memory when RLS is idle, and doing so is fairly reasonable in the compiler but less so in RLS.
Procedural macros authors assume compilation is a batch job / short lived. We can see this with "conflicting implementation of trait" with enum_dispatch crate #1212 where a proc-macro's use of mutable statics means RLS encounters bugs that are not easily encountered with cargo. It also mean proc-macros may consume memory while RLS is idle.
-
Compiles cannot be cancelled. This is an old annoyance of mine about RLS, in this way RLS is inferior to
cargo watch -x check. Processes can be cancelled, and the compiler handles such cancellations pretty well. Threads cannot be cancelled in the same way. It would be a big performance improvement to RLS to be able to simply cancel the current compiler run after a source change, allowing the next compile run to start immediately. -
Compiler & procedural macros can very easily print to stdout. This basically kills RLS because we use RLS stdout exclusively for LSP comms and the LSP client libs cannot handle garbage.
Vfs cross-process
The main barrier, it seems, then is getting Vfs to work cross-process. If this is possible we can start the compiler in a new process. It would also unlock further improvements.
- Racer and any such expensive tasks could be run in a separate process. Allowing cancellation and stdout/static memory isolation.
So can we make Vfs work with the compiler in another process?
Are there other benefits of working in-process?