From c1a31d4261afda9839020f772fd6a97a12d9c941 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 24 Apr 2020 23:30:49 -0400 Subject: [PATCH 1/2] main: eagerly prime goto-definition caches This commit makes RA more aggressive about eagerly priming the caches. In particular, this fixes an issue where even after RA was done priming its caches, an initial goto-definition request would have very high latency. This fixes that issue by requesting syntax highlighting for everything. It is presumed that this is a tad wasteful, but not overly so. This commit also tweaks the logic that determines when the cache is primed. Namely, instead of just priming it when the state is loaded initially, we attempt to prime it whenever some state changes. This fixes an issue where if a modification notification is seen before cache priming is done, it would stop the cache priming early. --- crates/ra_ide/src/prime_caches.rs | 5 +---- crates/rust-analyzer/src/main_loop.rs | 15 ++++++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/crates/ra_ide/src/prime_caches.rs b/crates/ra_ide/src/prime_caches.rs index 628c989bfc..90bf7d25f2 100644 --- a/crates/ra_ide/src/prime_caches.rs +++ b/crates/ra_ide/src/prime_caches.rs @@ -3,13 +3,10 @@ //! request takes longer to compute. This modules implemented prepopulating of //! various caches, it's not really advanced at the moment. -use hir::Semantics; - use crate::{FileId, RootDatabase}; pub(crate) fn prime_caches(db: &RootDatabase, files: Vec) { - let sema = Semantics::new(db); for file in files { - let _ = sema.to_module_def(file); + let _ = crate::syntax_highlighting::highlight(db, file, None); } } diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index fc4c77f8aa..c03d3db759 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -417,28 +417,29 @@ fn loop_turn( && loop_state.pending_libraries.is_empty() && loop_state.in_flight_libraries == 0 { + state_changed = true; loop_state.workspace_loaded = true; if let Some(flycheck) = &world_state.flycheck { flycheck.update(); } - pool.execute({ - let subs = loop_state.subscriptions.subscriptions(); - let snap = world_state.snapshot(); - move || snap.analysis().prime_caches(subs).unwrap_or_else(|_: Canceled| ()) - }); } if show_progress { send_startup_progress(&connection.sender, loop_state); } - if state_changed { + if state_changed && loop_state.workspace_loaded { update_file_notifications_on_threadpool( pool, world_state.snapshot(), task_sender.clone(), loop_state.subscriptions.subscriptions(), - ) + ); + pool.execute({ + let subs = loop_state.subscriptions.subscriptions(); + let snap = world_state.snapshot(); + move || snap.analysis().prime_caches(subs).unwrap_or_else(|_: Canceled| ()) + }); } let loop_duration = loop_start.elapsed(); From 0c12b7e8c8605e84873858da0c4aa170140c14bb Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 25 Apr 2020 10:26:33 -0400 Subject: [PATCH 2/2] main: fix bug where thread pool isn't joined Pointed out here: https://github.com/rust-analyzer/rust-analyzer/pull/4133#issuecomment-619386272 --- crates/rust-analyzer/src/main_loop.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index c03d3db759..7f6f4ec12a 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -222,6 +222,7 @@ pub fn main_loop(ws_roots: Vec, config: Config, connection: Connection) libdata_receiver.into_iter().for_each(drop); log::info!("...tasks have finished"); log::info!("joining threadpool..."); + pool.join(); drop(pool); log::info!("...threadpool has finished");