diff options
author | Andrew Gallant <[email protected]> | 2020-04-25 04:30:49 +0100 |
---|---|---|
committer | Andrew Gallant <[email protected]> | 2020-04-25 14:28:34 +0100 |
commit | c1a31d4261afda9839020f772fd6a97a12d9c941 (patch) | |
tree | 63a25a71915e58b5996fed3b9f4062ac2b317a00 /crates | |
parent | 27a7718880d93f55f905da606d108d3b3c682ab4 (diff) |
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.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/prime_caches.rs | 5 | ||||
-rw-r--r-- | 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 628c989bf..90bf7d25f 100644 --- a/crates/ra_ide/src/prime_caches.rs +++ b/crates/ra_ide/src/prime_caches.rs | |||
@@ -3,13 +3,10 @@ | |||
3 | //! request takes longer to compute. This modules implemented prepopulating of | 3 | //! request takes longer to compute. This modules implemented prepopulating of |
4 | //! various caches, it's not really advanced at the moment. | 4 | //! various caches, it's not really advanced at the moment. |
5 | 5 | ||
6 | use hir::Semantics; | ||
7 | |||
8 | use crate::{FileId, RootDatabase}; | 6 | use crate::{FileId, RootDatabase}; |
9 | 7 | ||
10 | pub(crate) fn prime_caches(db: &RootDatabase, files: Vec<FileId>) { | 8 | pub(crate) fn prime_caches(db: &RootDatabase, files: Vec<FileId>) { |
11 | let sema = Semantics::new(db); | ||
12 | for file in files { | 9 | for file in files { |
13 | let _ = sema.to_module_def(file); | 10 | let _ = crate::syntax_highlighting::highlight(db, file, None); |
14 | } | 11 | } |
15 | } | 12 | } |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index fc4c77f8a..c03d3db75 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -417,28 +417,29 @@ fn loop_turn( | |||
417 | && loop_state.pending_libraries.is_empty() | 417 | && loop_state.pending_libraries.is_empty() |
418 | && loop_state.in_flight_libraries == 0 | 418 | && loop_state.in_flight_libraries == 0 |
419 | { | 419 | { |
420 | state_changed = true; | ||
420 | loop_state.workspace_loaded = true; | 421 | loop_state.workspace_loaded = true; |
421 | if let Some(flycheck) = &world_state.flycheck { | 422 | if let Some(flycheck) = &world_state.flycheck { |
422 | flycheck.update(); | 423 | flycheck.update(); |
423 | } | 424 | } |
424 | pool.execute({ | ||
425 | let subs = loop_state.subscriptions.subscriptions(); | ||
426 | let snap = world_state.snapshot(); | ||
427 | move || snap.analysis().prime_caches(subs).unwrap_or_else(|_: Canceled| ()) | ||
428 | }); | ||
429 | } | 425 | } |
430 | 426 | ||
431 | if show_progress { | 427 | if show_progress { |
432 | send_startup_progress(&connection.sender, loop_state); | 428 | send_startup_progress(&connection.sender, loop_state); |
433 | } | 429 | } |
434 | 430 | ||
435 | if state_changed { | 431 | if state_changed && loop_state.workspace_loaded { |
436 | update_file_notifications_on_threadpool( | 432 | update_file_notifications_on_threadpool( |
437 | pool, | 433 | pool, |
438 | world_state.snapshot(), | 434 | world_state.snapshot(), |
439 | task_sender.clone(), | 435 | task_sender.clone(), |
440 | loop_state.subscriptions.subscriptions(), | 436 | loop_state.subscriptions.subscriptions(), |
441 | ) | 437 | ); |
438 | pool.execute({ | ||
439 | let subs = loop_state.subscriptions.subscriptions(); | ||
440 | let snap = world_state.snapshot(); | ||
441 | move || snap.analysis().prime_caches(subs).unwrap_or_else(|_: Canceled| ()) | ||
442 | }); | ||
442 | } | 443 | } |
443 | 444 | ||
444 | let loop_duration = loop_start.elapsed(); | 445 | let loop_duration = loop_start.elapsed(); |