From 66ed821e18eadd3930a8621095c90b142763d517 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 Jan 2021 15:46:31 +0300 Subject: Speed up snapshoting Config can be fairly big, no need to deep clone it frequently --- crates/rust-analyzer/src/global_state.rs | 8 ++++---- crates/rust-analyzer/src/main_loop.rs | 2 +- crates/rust-analyzer/src/reload.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 19ab4d596..1f6bf1c8c 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -67,7 +67,7 @@ pub(crate) struct GlobalState { pub(crate) flycheck: Vec, pub(crate) flycheck_sender: Sender, pub(crate) flycheck_receiver: Receiver, - pub(crate) config: Config, + pub(crate) config: Arc, pub(crate) analysis_host: AnalysisHost, pub(crate) diagnostics: DiagnosticCollection, pub(crate) mem_docs: FxHashMap, @@ -83,7 +83,7 @@ pub(crate) struct GlobalState { /// An immutable snapshot of the world's state at a point in time. pub(crate) struct GlobalStateSnapshot { - pub(crate) config: Config, + pub(crate) config: Arc, pub(crate) analysis: Analysis, pub(crate) check_fixes: CheckFixes, pub(crate) latest_requests: Arc>, @@ -119,7 +119,7 @@ impl GlobalState { flycheck: Vec::new(), flycheck_sender, flycheck_receiver, - config, + config: Arc::new(config), analysis_host, diagnostics: Default::default(), mem_docs: FxHashMap::default(), @@ -184,7 +184,7 @@ impl GlobalState { pub(crate) fn snapshot(&self) -> GlobalStateSnapshot { GlobalStateSnapshot { - config: self.config.clone(), + config: Arc::clone(&self.config), workspaces: Arc::clone(&self.workspaces), analysis: self.analysis_host.analysis(), vfs: Arc::clone(&self.vfs), diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 53f9546b8..7ac6acf70 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -609,7 +609,7 @@ impl GlobalState { if let Some(json) = configs.get_mut(0) { // Note that json can be null according to the spec if the client can't // provide a configuration. This is handled in Config::update below. - let mut config = this.config.clone(); + let mut config = Config::clone(&*this.config); config.update(json.take()); this.update_configuration(config); } diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 51c24e966..76b50931a 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -18,7 +18,7 @@ use lsp_ext::StatusParams; impl GlobalState { pub(crate) fn update_configuration(&mut self, config: Config) { let _p = profile::span("GlobalState::update_configuration"); - let old_config = mem::replace(&mut self.config, config); + let old_config = mem::replace(&mut self.config, Arc::new(config)); if self.config.lru_capacity() != old_config.lru_capacity() { self.analysis_host.update_lru_capacity(self.config.lru_capacity()); } -- cgit v1.2.3