mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-31 00:12:06 +00:00
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.
This commit is contained in:
parent
1fa88dbad0
commit
7bf1ab712a
1 changed files with 15 additions and 6 deletions
|
@ -173,22 +173,31 @@ pub fn snapshot_progress(ui: &mut Ui) -> Option<impl Fn(&RepoPath) + '_> {
|
||||||
struct State<'a> {
|
struct State<'a> {
|
||||||
guard: Option<OutputGuard>,
|
guard: Option<OutputGuard>,
|
||||||
ui: &'a mut Ui,
|
ui: &'a mut Ui,
|
||||||
|
next_display_time: Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ui.use_progress_indicator() {
|
if !ui.use_progress_indicator() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let start = Instant::now();
|
// Don't clutter the output during fast operations.
|
||||||
let state = Mutex::new(State { guard: None, ui });
|
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| {
|
Some(move |path: &RepoPath| {
|
||||||
if start.elapsed() < Duration::from_millis(250) {
|
let mut state = state.lock().unwrap();
|
||||||
// Don't clutter the output during fast operations. Future work: Display current
|
let now = Instant::now();
|
||||||
// path after exactly 250ms has elapsed, to better handle large single files
|
if now < state.next_display_time {
|
||||||
|
// Future work: Display current path after exactly, say, 250ms has elapsed, to
|
||||||
|
// better handle large single files
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut state = state.lock().unwrap();
|
state.next_display_time = now + Duration::from_millis(10);
|
||||||
|
|
||||||
if state.guard.is_none() {
|
if state.guard.is_none() {
|
||||||
state.guard = Some(
|
state.guard = Some(
|
||||||
state
|
state
|
||||||
|
|
Loading…
Reference in a new issue