Skip to content

Commit eb4e84f

Browse files
bors[bot]Jonas Schievink
andauthored
Merge #6441
6441: Coalesce prime_caches updates r=matklad a=jonas-schievink This reduces the number of progress bar updates we send to the client by collapsing subsequent updates into one. This doesn't work as well as I'd hoped (which is that we end up sending *no* updates, or only `start` and `end`, when the cache is already fresh), but it does reduce the number considerably: instead of ~720 updates on the rust-analyzer codebase, we now only send ~60. It uses the same approach that is already in use for coalescing VFS events. Hopefully this is enough to fix #6413. Co-authored-by: Jonas Schievink <[email protected]>
2 parents 4e80002 + a968cb6 commit eb4e84f

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

crates/rust-analyzer/src/main_loop.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,35 @@ impl GlobalState {
190190
}
191191
lsp_server::Message::Response(resp) => self.complete_request(resp),
192192
},
193-
Event::Task(task) => match task {
194-
Task::Response(response) => self.respond(response),
195-
Task::Diagnostics(diagnostics_per_file) => {
196-
for (file_id, diagnostics) in diagnostics_per_file {
197-
self.diagnostics.set_native_diagnostics(file_id, diagnostics)
193+
Event::Task(mut task) => {
194+
let _p = profile::span("GlobalState::handle_event/task");
195+
let mut prime_caches_started = false;
196+
let mut prime_caches_progress = None;
197+
loop {
198+
match task {
199+
Task::Response(response) => self.respond(response),
200+
Task::Diagnostics(diagnostics_per_file) => {
201+
for (file_id, diagnostics) in diagnostics_per_file {
202+
self.diagnostics.set_native_diagnostics(file_id, diagnostics)
203+
}
204+
}
205+
Task::Workspaces(workspaces) => self.switch_workspaces(workspaces),
206+
Task::PrimeCaches(progress) => {
207+
if let PrimeCachesProgress::Started = progress {
208+
prime_caches_started = true;
209+
}
210+
211+
prime_caches_progress = Some(progress);
212+
}
198213
}
214+
// Coalesce multiple task events into one loop turn
215+
task = match self.task_pool.receiver.try_recv() {
216+
Ok(task) => task,
217+
Err(_) => break,
218+
};
199219
}
200-
Task::Workspaces(workspaces) => self.switch_workspaces(workspaces),
201-
Task::PrimeCaches(progress) => {
220+
221+
if let Some(progress) = prime_caches_progress {
202222
let (state, message, fraction);
203223
match progress {
204224
PrimeCachesProgress::Started => {
@@ -218,9 +238,14 @@ impl GlobalState {
218238
}
219239
};
220240

221-
self.report_progress("indexing", state, message, Some(fraction));
241+
if state != Progress::Begin && prime_caches_started {
242+
// Progress indicator needs to be created first.
243+
self.report_progress("indexing", Progress::Begin, None, Some(0.0));
244+
}
245+
246+
self.report_progress("indexing", state, message.clone(), Some(fraction));
222247
}
223-
},
248+
}
224249
Event::Vfs(mut task) => {
225250
let _p = profile::span("GlobalState::handle_event/vfs");
226251
loop {

0 commit comments

Comments
 (0)