Skip to content

Commit e5e5d21

Browse files
committed
Auto merge of #11800 - Byron:progress-bar-fixes, r=weihanglo
gitoxide progress bar fixes This PR makes the progress bar shown when fetching git repositories with `-Zgitoxide` feel more similar to the `git2` implementation. The main difference is that it separates the indexing and delta-resolution stage at 50%, instead of at ~33%. Furthermore it 'cools' the hot loop that was dealing with progress display, which previously used one whole core. Here is how it looks now: [![asciicast](https://asciinema.org/a/loJcLDNng0H9fSWkzDmA2u2e0.svg)](https://asciinema.org/a/loJcLDNng0H9fSWkzDmA2u2e0) ### Videos * how it looks with `git2` https://user-images.githubusercontent.com/63622/222902630-9cc5cd60-beff-4a70-a791-c264aec46e3b.mov * `gitoxide` before the fix: https://user-images.githubusercontent.com/63622/222902777-1272982c-8c35-4b41-8350-80ac0f2296de.mov * and `gitoxide` after the fix: https://user-images.githubusercontent.com/63622/222902878-9f35d9a9-9603-49d4-b751-e05884684d52.mov
2 parents 8ef74af + 789efe3 commit e5e5d21

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ filetime = "0.2.9"
3030
flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] }
3131
git2 = "0.16.0"
3232
git2-curl = "0.17.0"
33-
gix = { version = "0.38.0", default-features = false, features = ["blocking-http-transport-curl", "progress-tree"] }
34-
gix-features-for-configuration-only = { version = "0.27.0", package = "gix-features", features = [ "parallel" ] }
33+
gix = { version = "0.39.0", default-features = false, features = ["blocking-http-transport-curl", "progress-tree"] }
34+
gix-features-for-configuration-only = { version = "0.28.0", package = "gix-features", features = [ "parallel" ] }
3535
glob = "0.3.0"
3636
hex = "0.4"
3737
hmac = "0.12.1"

src/cargo/sources/git/oxide.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,34 @@ fn translate_progress_to_bar(
6969

7070
// We choose `N=10` here to make a `300ms * 10slots ~= 3000ms`
7171
// sliding window for tracking the data transfer rate (in bytes/s).
72-
let mut last_update = Instant::now();
73-
let mut counter = MetricsCounter::<10>::new(0, last_update);
72+
let mut last_percentage_update = Instant::now();
73+
let mut last_fast_update = Instant::now();
74+
let mut counter = MetricsCounter::<10>::new(0, last_percentage_update);
7475

7576
let mut tasks = Vec::with_capacity(10);
76-
let update_interval = std::time::Duration::from_millis(300);
77-
let short_check_interval = Duration::from_millis(50);
77+
let slow_check_interval = std::time::Duration::from_millis(300);
78+
let fast_check_interval = Duration::from_millis(50);
79+
let sleep_interval = Duration::from_millis(10);
80+
debug_assert_eq!(
81+
slow_check_interval.as_millis() % fast_check_interval.as_millis(),
82+
0,
83+
"progress should be smoother by keeping these as multiples of each other"
84+
);
85+
debug_assert_eq!(
86+
fast_check_interval.as_millis() % sleep_interval.as_millis(),
87+
0,
88+
"progress should be smoother by keeping these as multiples of each other"
89+
);
7890

7991
while let Some(root) = root.upgrade() {
80-
let not_yet = last_update.elapsed() < update_interval;
81-
if not_yet {
82-
std::thread::sleep(short_check_interval);
92+
std::thread::sleep(sleep_interval);
93+
let needs_update = last_fast_update.elapsed() >= fast_check_interval;
94+
if !needs_update {
95+
continue;
8396
}
97+
let now = Instant::now();
98+
last_fast_update = now;
99+
84100
root.sorted_snapshot(&mut tasks);
85101

86102
fn progress_by_id(
@@ -96,13 +112,14 @@ fn translate_progress_to_bar(
96112
tasks.iter().find_map(|(_, t)| cb(t))
97113
}
98114

115+
const NUM_PHASES: usize = 2; // indexing + delta-resolution, both with same amount of objects to handle
99116
if let Some(objs) = find_in(&tasks, |t| progress_by_id(resolve_objects, t)) {
100117
// Resolving deltas.
101118
let objects = objs.step.load(Ordering::Relaxed);
102119
let total_objects = objs.done_at.expect("known amount of objects");
103120
let msg = format!(", ({objects}/{total_objects}) resolving deltas");
104121

105-
progress_bar.tick(objects, total_objects, &msg)?;
122+
progress_bar.tick(total_objects + objects, total_objects * NUM_PHASES, &msg)?;
106123
} else if let Some((objs, read_pack)) =
107124
find_in(&tasks, |t| progress_by_id(read_pack_bytes, t)).and_then(|read| {
108125
find_in(&tasks, |t| progress_by_id(delta_index_objects, t))
@@ -114,15 +131,15 @@ fn translate_progress_to_bar(
114131
let total_objects = objs.done_at.expect("known amount of objects");
115132
let received_bytes = read_pack.step.load(Ordering::Relaxed);
116133

117-
let now = Instant::now();
118-
if !not_yet {
134+
let needs_percentage_update = last_percentage_update.elapsed() >= slow_check_interval;
135+
if needs_percentage_update {
119136
counter.add(received_bytes, now);
120-
last_update = now;
137+
last_percentage_update = now;
121138
}
122139
let (rate, unit) = human_readable_bytes(counter.rate() as u64);
123140
let msg = format!(", {rate:.2}{unit}/s");
124141

125-
progress_bar.tick(objects, total_objects, &msg)?;
142+
progress_bar.tick(objects, total_objects * NUM_PHASES, &msg)?;
126143
}
127144
}
128145
Ok(())

0 commit comments

Comments
 (0)