diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-01-15 15:37:28 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-01-15 15:37:28 +0000 |
commit | c0661ce7444223b0fff1f5d54adb41022ab788cb (patch) | |
tree | 24aa00d87f5a90d10d0ec37178331ec1c3f9428a /crates/ra_vfs_glob/Cargo.toml | |
parent | 80136367682ced76fb1a74403435c742685620c8 (diff) | |
parent | 7a8c6351bf50c1dcfb111be9f91da3c1f9cf2ec3 (diff) |
Merge #2853
2853: Manage `cargo check` state updates in `main_loop` to reduce lock contention r=matklad a=kiljacken
State is now updated exclusively from `main_loop` so several threads theoretically can't compete for the lock. Updates to the state are requested via the existing task channel.
Also updates some naming to make slightly more sense.
Based upon an idea/suggestion from @matklad on Zulip:
> I think I've noticed at leas something suspicious!
>
> In WorldSnapshot, we store an Arc<RwLock<CheckWatcherSharedState>>. We read lock this lock in handle_diagnostics.
>
> Additionally, we .write this lock from the watcher thread in CheckWatcherState::run.
>
> I think in general this is less then ideal, b/c diagnostics request can be blocked on another thread. I think it makes sense to architect this in a way which does not block.
>
> For that, we stop sharing the state between ServerWorld and CheckWatcherState. Instead, the watcher thread sends new diagnostics via a channel, and we accomodate thouse diagnostics intot he server state in the main loop.
>
> So, instead of:
> ```rust
> struct Server {
> diagnostics: Arc<Mutex<Vec<Diagnostics>>>,
> }
>
> struct Watcher {
> diagnostics: Arc<Mutex<Vec<Diagnostics>>>,
> }
> ```
> we'll have something like this:
> ```rust
> struct Server {
> // this bit now *owns* diagnostics
> diagnostisc: Vec<Diagnostics>
> }
>
> struct Watcher {
> diagnostics_sink: Sender<Vec<Diagnostics>>,
> }
> ```
> I am not sure this is the cuprit of slowness on widnows, but I think we should fix it, because it's very useful when all changes to the server's state can occur only via the main loop.
>
> Note how VFS is set up in a similar way: instead of modifing some global hash map with files, VFS sends a message to the main looop that hey, I have these new files for you. The main loop than incorporates the changes itself.
>
> Note that I think we'll still need some locks here, to share the state between ServerWorld and WorldSnapshot, but we won't actually be changing anyting mid-snapshot
Co-authored-by: Emil Lauridsen <[email protected]>
Diffstat (limited to 'crates/ra_vfs_glob/Cargo.toml')
0 files changed, 0 insertions, 0 deletions