From 7bf1ab712a001ef90bae41b7756dd52d9d01c1a4 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 26 May 2023 09:01:22 -0700 Subject: [PATCH] progress: update progress only every 10 ms In the Linux repo, this speeds up `jj diff` in a clean working copy from 1.41 s to 881 ms. --- src/progress.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/progress.rs b/src/progress.rs index 125893232..aa838d4e8 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -173,22 +173,31 @@ pub fn snapshot_progress(ui: &mut Ui) -> Option { struct State<'a> { guard: Option, ui: &'a mut Ui, + next_display_time: Instant, } if !ui.use_progress_indicator() { return None; } - let start = Instant::now(); - let state = Mutex::new(State { guard: None, ui }); + // Don't clutter the output during fast operations. + let next_display_time = Instant::now() + Duration::from_millis(250); + let state = Mutex::new(State { + guard: None, + ui, + next_display_time, + }); Some(move |path: &RepoPath| { - if start.elapsed() < Duration::from_millis(250) { - // Don't clutter the output during fast operations. Future work: Display current - // path after exactly 250ms has elapsed, to better handle large single files + let mut state = state.lock().unwrap(); + let now = Instant::now(); + if now < state.next_display_time { + // Future work: Display current path after exactly, say, 250ms has elapsed, to + // better handle large single files return; } - let mut state = state.lock().unwrap(); + state.next_display_time = now + Duration::from_millis(10); + if state.guard.is_none() { state.guard = Some( state