Skip to content

Commit c1a31d4

Browse files
committed
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.
1 parent 27a7718 commit c1a31d4

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

crates/ra_ide/src/prime_caches.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
//! request takes longer to compute. This modules implemented prepopulating of
44
//! various caches, it's not really advanced at the moment.
55
6-
use hir::Semantics;
7-
86
use crate::{FileId, RootDatabase};
97

108
pub(crate) fn prime_caches(db: &RootDatabase, files: Vec<FileId>) {
11-
let sema = Semantics::new(db);
129
for file in files {
13-
let _ = sema.to_module_def(file);
10+
let _ = crate::syntax_highlighting::highlight(db, file, None);
1411
}
1512
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,28 +417,29 @@ fn loop_turn(
417417
&& loop_state.pending_libraries.is_empty()
418418
&& loop_state.in_flight_libraries == 0
419419
{
420+
state_changed = true;
420421
loop_state.workspace_loaded = true;
421422
if let Some(flycheck) = &world_state.flycheck {
422423
flycheck.update();
423424
}
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-
});
429425
}
430426

431427
if show_progress {
432428
send_startup_progress(&connection.sender, loop_state);
433429
}
434430

435-
if state_changed {
431+
if state_changed && loop_state.workspace_loaded {
436432
update_file_notifications_on_threadpool(
437433
pool,
438434
world_state.snapshot(),
439435
task_sender.clone(),
440436
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+
});
442443
}
443444

444445
let loop_duration = loop_start.elapsed();

0 commit comments

Comments
 (0)