Fix batch enumeration offsets and refactor sibling annex construction
Shifts sibling annex construction from slot-indexed enumeration to iteration-order traversal by correcting cumulative k-mer offset tracking in batch enumeration. Replaces coarse per-partition parallelism with chunked work distribution to prevent thread starvation on skewed partitions. Decouples custom progress messages from ETA updates to eliminate display clobbering during high-frequency callbacks. Adds regression tests validating batch offset correctness, partial batch handling, and iterator-order consistency across layer builds.
This commit is contained in:
1 parent
d2548e8c33
commit
32d6720f50
11 files changed
+413
-88
No files matched your search
+34
-15
@@ -1,4 +1,5 @@
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::Mutex;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
@@ -7,7 +8,6 @@ use tracing::{debug, info};
|
||||
const BRAILLE: &[&str] = &["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
||||
const ETA_REFRESH_MS: u64 = 500;
|
||||
const ETA_MIN_ELAPSED_MS: u64 = 1000;
|
||||
const ETA_CUSTOM_HOLD_MS: u64 = 2000;
|
||||
|
||||
pub struct TracedBar {
|
||||
pb: ProgressBar,
|
||||
@@ -18,7 +18,16 @@ pub struct TracedBar {
|
||||
last_pct: AtomicU64,
|
||||
last_log_ms: AtomicU64,
|
||||
last_eta_refresh: AtomicU64,
|
||||
last_custom_msg_ms: AtomicU64,
|
||||
/// Caller-supplied text (via [`set_message`](Self::set_message)) and the
|
||||
/// self-computed ETA text are two independent pieces of information that
|
||||
/// used to fight over indicatif's single `{msg}` slot — whichever wrote
|
||||
/// last would silently clobber the other, and a caller that calls
|
||||
/// `set_message` more often than the ETA's hold window (as
|
||||
/// `build_sibling_annex`'s per-partition callback does once several
|
||||
/// partitions run concurrently) starved the ETA out entirely. Kept as
|
||||
/// separate strings, composed together on every render instead.
|
||||
custom_text: Mutex<String>,
|
||||
eta_text: Mutex<String>,
|
||||
}
|
||||
|
||||
impl TracedBar {
|
||||
@@ -48,6 +57,21 @@ impl TracedBar {
|
||||
}
|
||||
}
|
||||
|
||||
/// Recompose the displayed message from `custom_text` + `eta_text` and
|
||||
/// push it as one `pb.set_message` call — the two pieces never compete
|
||||
/// for the slot, they always coexist.
|
||||
fn render(&self) {
|
||||
let custom = self.custom_text.lock().unwrap();
|
||||
let eta = self.eta_text.lock().unwrap();
|
||||
let combined = match (custom.is_empty(), eta.is_empty()) {
|
||||
(true, true) => String::new(),
|
||||
(false, true) => custom.clone(),
|
||||
(true, false) => eta.clone(),
|
||||
(false, false) => format!("{custom} {eta}"),
|
||||
};
|
||||
self.pb.set_message(combined);
|
||||
}
|
||||
|
||||
fn maybe_update_eta(&self) {
|
||||
let now_ms = self.start.elapsed().as_millis() as u64;
|
||||
|
||||
@@ -60,11 +84,6 @@ impl TracedBar {
|
||||
return;
|
||||
}
|
||||
|
||||
let last_custom = self.last_custom_msg_ms.load(Ordering::Relaxed);
|
||||
if now_ms < last_custom + ETA_CUSTOM_HOLD_MS {
|
||||
return;
|
||||
}
|
||||
|
||||
let pos = self.pb.position();
|
||||
let remaining = self.total - pos;
|
||||
|
||||
@@ -76,7 +95,8 @@ impl TracedBar {
|
||||
let avg_rate = pos as f64 / elapsed_secs;
|
||||
let eta_secs = remaining as f64 / avg_rate;
|
||||
|
||||
self.pb.set_message(format!("(eta: {})", fmt_secs(eta_secs)));
|
||||
*self.eta_text.lock().unwrap() = format!("(eta: {})", fmt_secs(eta_secs));
|
||||
self.render();
|
||||
|
||||
let _ = self.last_eta_refresh.compare_exchange(
|
||||
last,
|
||||
@@ -88,10 +108,6 @@ impl TracedBar {
|
||||
|
||||
pub fn set_message(&self, msg: impl Into<String>) {
|
||||
let msg = msg.into();
|
||||
self.last_custom_msg_ms.store(
|
||||
self.start.elapsed().as_millis() as u64,
|
||||
Ordering::Relaxed,
|
||||
);
|
||||
if self.pb.is_hidden() {
|
||||
if self.total > 0 {
|
||||
debug!(stage = %self.label, "{msg}");
|
||||
@@ -108,7 +124,8 @@ impl TracedBar {
|
||||
}
|
||||
}
|
||||
}
|
||||
self.pb.set_message(msg);
|
||||
*self.custom_text.lock().unwrap() = msg;
|
||||
self.render();
|
||||
}
|
||||
|
||||
pub fn finish_and_clear(&self) {
|
||||
@@ -147,7 +164,8 @@ pub fn spinner(label: &str) -> TracedBar {
|
||||
last_pct: AtomicU64::new(0),
|
||||
last_log_ms: AtomicU64::new(0),
|
||||
last_eta_refresh: AtomicU64::new(0),
|
||||
last_custom_msg_ms: AtomicU64::new(0),
|
||||
custom_text: Mutex::new(String::new()),
|
||||
eta_text: Mutex::new(String::new()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,6 +190,7 @@ pub fn progress_bar(label: &str, n: u64, unit: &str) -> TracedBar {
|
||||
last_pct: AtomicU64::new(0),
|
||||
last_log_ms: AtomicU64::new(0),
|
||||
last_eta_refresh: AtomicU64::new(0),
|
||||
last_custom_msg_ms: AtomicU64::new(0),
|
||||
custom_text: Mutex::new(String::new()),
|
||||
eta_text: Mutex::new(String::new()),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user