Closed mtkennerly closed 3 months ago
So, (a) we only update the progress bars when some method on the ProgressBar
is called (for the non-parallel case, inc(1)
for every call to Iterator::next()
). Then we also rate limit draws (by default, to 20 times/s), so if inc()
is called a bunch of times in a short time window, not all of those trigger a redraw.
For parallel iterators, the situation is a bit more complex, I suggest reading the code at https://github.com/console-rs/indicatif/blob/main/src/rayon.rs and maybe inserting some debug prints to see what's going on. I could see how rayon might be pushing a chunk at a time and the progress bar only getting in one draw per chunk.
(Sorry for the slow response, you caught me in a busy week so took some time to loop back to this.)
I just noticed the enable_steady_tick
option, which solves this problem for me. I guess it was there the whole time and I just missed it 😅
In this example, elapsed
and elapsed_precise
update at different times, which seems a bit odd, but you probably wouldn't use both together anyway.
diff --git a/src/main.rs b/src/main.rs
index 4f49d00..49ce520 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,6 +7,7 @@ fn main() {
let template = "{elapsed}, {elapsed_precise} {wide_bar} {pos} / {len}";
let style = ProgressStyle::default_bar().template(&template).unwrap();
let bar = ProgressBar::new(xs.len() as u64).with_style(style);
+ bar.enable_steady_tick(Duration::from_millis(100));
_ = xs.iter().progress_with(bar).map(|_| {
thread::sleep(Duration::from_secs(3));
https://github.com/console-rs/indicatif/assets/4934192/395a9b9f-080a-4feb-8193-b9528b5f00dc
I'm not sure if this is a bug or an intentional design, but I noticed that
elapsed
/elapsed_precise
don't update while a single step is running. I can definitely understand that for single-threaded iterators, but I was surprised that it's also true for parallel iterators. What would be the recommended way to handle this?Also, with the parallel iterator, 16 of the iterations don't cause the progress bar to update. Incidentally, my system has 16 cores. It seems like I have to have more than 16 items in the iterator to see any updates.
Single-threaded
Cargo.toml
main.rs
Output
Parallel
Cargo.toml
main.rs
Output