From 05aa5b854b230c2f6ba182c0f2c94f3de9a47204 Mon Sep 17 00:00:00 2001 From: Emil Lauridsen Date: Thu, 23 Jan 2020 09:26:08 +0100 Subject: Remove RWLock from check watcher. @matklad mentioned this might be a good idea. So the general idea is that we don't really need the lock, as we can just clone the check watcher state when creating a snapshot. We can then use `Arc::get_mut` to get mutable access to the state from `WorldState` when needed. Running with this it seems to improve responsiveness a bit while cargo is running, but I have no hard numbers to prove it. In any case, a serialization point less is always better when we're trying to be responsive. --- crates/ra_cargo_watch/src/conv.rs | 2 +- crates/ra_cargo_watch/src/lib.rs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'crates/ra_cargo_watch') diff --git a/crates/ra_cargo_watch/src/conv.rs b/crates/ra_cargo_watch/src/conv.rs index ac0f1d28a..8fba400ae 100644 --- a/crates/ra_cargo_watch/src/conv.rs +++ b/crates/ra_cargo_watch/src/conv.rs @@ -117,7 +117,7 @@ fn is_deprecated(rd: &RustDiagnostic) -> bool { } } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct SuggestedFix { pub title: String, pub location: Location, diff --git a/crates/ra_cargo_watch/src/lib.rs b/crates/ra_cargo_watch/src/lib.rs index 7f4c9280c..bbe634603 100644 --- a/crates/ra_cargo_watch/src/lib.rs +++ b/crates/ra_cargo_watch/src/lib.rs @@ -7,7 +7,6 @@ use lsp_types::{ Diagnostic, Url, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressEnd, WorkDoneProgressReport, }; -use parking_lot::RwLock; use std::{ collections::HashMap, path::PathBuf, @@ -38,7 +37,7 @@ pub struct CheckOptions { #[derive(Debug)] pub struct CheckWatcher { pub task_recv: Receiver, - pub state: Arc>, + pub state: Arc, cmd_send: Option>, handle: Option>, } @@ -46,7 +45,7 @@ pub struct CheckWatcher { impl CheckWatcher { pub fn new(options: &CheckOptions, workspace_root: PathBuf) -> CheckWatcher { let options = options.clone(); - let state = Arc::new(RwLock::new(CheckState::new())); + let state = Arc::new(CheckState::new()); let (task_send, task_recv) = unbounded::(); let (cmd_send, cmd_recv) = unbounded::(); @@ -59,7 +58,7 @@ impl CheckWatcher { /// Returns a CheckWatcher that doesn't actually do anything pub fn dummy() -> CheckWatcher { - let state = Arc::new(RwLock::new(CheckState::new())); + let state = Arc::new(CheckState::new()); CheckWatcher { task_recv: never(), cmd_send: None, handle: None, state } } @@ -87,7 +86,7 @@ impl std::ops::Drop for CheckWatcher { } } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct CheckState { diagnostic_collection: HashMap>, suggested_fix_collection: HashMap>, -- cgit v1.2.3