Skip to content

Commit 293a2ac

Browse files
alanzmeta-codesync[bot]
authored andcommitted
Update loader progress on percent change only
Summary: A project can have thousands of files. We report loader progress as the VFS loader loads these, presented on the VS Code status bar as a percentage figure. This means that we send multiple duplicate messages while loading, as the percentage number changes relatively slowly compared to the number of files loaded. This onslaught of messages can however overload the LSP client, resulting in a status bar that does not accurately reflect the current ELP loading state as it updates from the backlog in a received queue of messages. ## This diff This diff reduces the number of messages sent, without losing any information, by keeping track of the current percentage value, and only sending a progress message when it changes. Reviewed By: TheGeorge Differential Revision: D84140378 fbshipit-source-id: 13fd4e39b87010c70b692abd7aeb15beddef2dbd
1 parent 98bba7a commit 293a2ac

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

crates/elp/src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ impl Server {
957957
self.transition(Status::Loading(pb));
958958
}
959959
LoadingProgress::Progress(n_done) => {
960-
if let Status::Loading(pb) = &self.status {
960+
if let Status::Loading(pb) = &mut self.status {
961961
pb.report(n_done, n_total);
962962
}
963963
}
@@ -1988,7 +1988,7 @@ impl Server {
19881988

19891989
fn update_eqwalize_all(
19901990
&mut self,
1991-
bar: ProgressBar,
1991+
mut bar: ProgressBar,
19921992
project_id: ProjectId,
19931993
project_name: String,
19941994
mut files: Vec<FileId>,

crates/elp/src/server/progress.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ pub struct ProgressBar {
172172
/// The message sent when sending the final end report.
173173
/// It is used in e2e tests to check for a specific task being done.
174174
end_message: String,
175+
current_percent: u32,
175176
}
176177

177178
impl ProgressBar {
@@ -196,21 +197,25 @@ impl ProgressBar {
196197
token,
197198
sender,
198199
end_message: title,
200+
current_percent: 0,
199201
}
200202
}
201203

202-
pub fn report(&self, done: usize, total: usize) {
204+
pub fn report(&mut self, done: usize, total: usize) {
203205
let percent_f = done as f64 / total.max(1) as f64;
204206
let percent = (percent_f * 100.0) as u32;
205-
let message = format!("{percent}%");
206-
let msg = WorkDoneProgress::Report(WorkDoneProgressReport {
207-
cancellable: None,
208-
message: Some(message),
209-
percentage: Some(percent),
210-
});
211-
// We do not update any associated telemetry here, it will
212-
// report on the whole bar at the end in the drop.
213-
send_progress(&self.sender, self.token.clone(), msg);
207+
if percent != self.current_percent {
208+
self.current_percent = percent;
209+
let message = format!("{percent}%");
210+
let msg = WorkDoneProgress::Report(WorkDoneProgressReport {
211+
cancellable: None,
212+
message: Some(message),
213+
percentage: Some(percent),
214+
});
215+
// We do not update any associated telemetry here, it will
216+
// report on the whole bar at the end in the drop.
217+
send_progress(&self.sender, self.token.clone(), msg);
218+
}
214219
}
215220

216221
pub fn end(self) {

0 commit comments

Comments
 (0)