Skip to content

Commit 1c0f780

Browse files
colin-hoColin HoColin Ho
authored
chore: Build progress bar only on first update (#3626)
Theres 2 progress bars for swordfish, a rust based one thats for terminals, and a python one thats for jupyter notebooks (uses tqdm). This pr makes it so that the tqdm bar is only rendered on first update (the rust based one is already lazy rendered), + increase the refresh rate of both progress bars to 500ms. native https://github.com/user-attachments/assets/c55e51a4-4919-4246-9add-2fe13d305435 py https://github.com/user-attachments/assets/8be184c5-5b48-4fee-9579-deb485f37e07 --------- Co-authored-by: Colin Ho <[email protected]> Co-authored-by: Colin Ho <[email protected]>
1 parent f9a89a7 commit 1c0f780

File tree

3 files changed

+26
-36
lines changed

3 files changed

+26
-36
lines changed

daft/runners/progress_bar.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,34 @@ def __init__(self) -> None:
114114
self._maxinterval = 5.0
115115
self.tqdm_mod = get_tqdm(False)
116116
self.pbars: dict[int, Any] = dict()
117+
self.bar_configs: dict[int, str] = dict()
118+
self.next_id = 0
117119

118-
def make_new_bar(self, bar_format: str, initial_message: str) -> int:
119-
pbar_id = len(self.pbars)
120-
self.pbars[pbar_id] = self.tqdm_mod(
121-
bar_format=bar_format,
122-
desc=initial_message,
123-
position=pbar_id,
124-
leave=False,
125-
mininterval=1.0,
126-
maxinterval=self._maxinterval,
127-
)
120+
def make_new_bar(self, bar_format: str) -> int:
121+
pbar_id = self.next_id
122+
self.next_id += 1
123+
self.bar_configs[pbar_id] = bar_format
128124
return pbar_id
129125

130126
def update_bar(self, pbar_id: int, message: str) -> None:
127+
if pbar_id not in self.pbars:
128+
if pbar_id not in self.bar_configs:
129+
raise ValueError(f"No bar configuration found for id {pbar_id}")
130+
bar_format = self.bar_configs[pbar_id]
131+
self.pbars[pbar_id] = self.tqdm_mod(
132+
bar_format=bar_format,
133+
position=pbar_id,
134+
leave=False,
135+
mininterval=1.0,
136+
maxinterval=self._maxinterval,
137+
)
138+
del self.bar_configs[pbar_id]
131139
self.pbars[pbar_id].set_description_str(message)
132140

133141
def close_bar(self, pbar_id: int) -> None:
134-
self.pbars[pbar_id].close()
135-
del self.pbars[pbar_id]
142+
if pbar_id in self.pbars:
143+
self.pbars[pbar_id].close()
144+
del self.pbars[pbar_id]
136145

137146
def close(self) -> None:
138147
for p in self.pbars.values():

src/daft-local-execution/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ impl ExecutionRuntimeContext {
166166
runtime_stats: Arc<RuntimeStatsContext>,
167167
) -> Option<Arc<OperatorProgressBar>> {
168168
if let Some(ref pb_manager) = self.progress_bar_manager {
169-
let pb = pb_manager
170-
.make_new_bar(color, prefix, show_received)
171-
.unwrap();
169+
let pb = pb_manager.make_new_bar(color, prefix).unwrap();
172170
Some(Arc::new(OperatorProgressBar::new(
173171
pb,
174172
runtime_stats,

src/daft-local-execution/src/progress_bar.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub trait ProgressBarManager {
2121
&self,
2222
color: ProgressBarColor,
2323
prefix: &str,
24-
show_received: bool,
2524
) -> DaftResult<Box<dyn ProgressBar>>;
2625

2726
fn close_all(&self) -> DaftResult<()>;
@@ -52,8 +51,8 @@ pub struct OperatorProgressBar {
5251
}
5352

5453
impl OperatorProgressBar {
55-
// 100ms = 100_000_000ns
56-
const UPDATE_INTERVAL: u64 = 100_000_000;
54+
// 500ms = 500_000_000ns
55+
const UPDATE_INTERVAL: u64 = 500_000_000;
5756

5857
pub fn new(
5958
progress_bar: Box<dyn ProgressBar>,
@@ -146,27 +145,19 @@ impl ProgressBarManager for IndicatifProgressBarManager {
146145
&self,
147146
color: ProgressBarColor,
148147
prefix: &str,
149-
show_received: bool,
150148
) -> DaftResult<Box<dyn ProgressBar>> {
151149
let template_str = format!(
152150
"🗡️ 🐟 {{spinner:.green}} {{prefix:.{color}/bold}} | [{{elapsed_precise}}] {{msg}}",
153151
color = color.to_str(),
154152
);
155153

156-
let initial_message = if show_received {
157-
"0 rows received, 0 rows emitted".to_string()
158-
} else {
159-
"0 rows emitted".to_string()
160-
};
161-
162154
let pb = indicatif::ProgressBar::new_spinner()
163155
.with_style(
164156
ProgressStyle::default_spinner()
165157
.template(template_str.as_str())
166158
.unwrap(),
167159
)
168-
.with_prefix(prefix.to_string())
169-
.with_message(initial_message);
160+
.with_prefix(prefix.to_string());
170161

171162
self.multi_progress.add(pb.clone());
172163
DaftResult::Ok(Box::new(IndicatifProgressBar(pb)))
@@ -263,18 +254,10 @@ mod python {
263254
&self,
264255
_color: ProgressBarColor,
265256
prefix: &str,
266-
show_received: bool,
267257
) -> DaftResult<Box<dyn ProgressBar>> {
268258
let bar_format = format!("🗡️ 🐟 {prefix}: {{elapsed}} {{desc}}", prefix = prefix);
269-
let initial_message = if show_received {
270-
"0 rows received, 0 rows emitted".to_string()
271-
} else {
272-
"0 rows emitted".to_string()
273-
};
274259
let pb_id = Python::with_gil(|py| {
275-
let pb_id =
276-
self.inner
277-
.call_method1(py, "make_new_bar", (bar_format, initial_message))?;
260+
let pb_id = self.inner.call_method1(py, "make_new_bar", (bar_format,))?;
278261
let pb_id = pb_id.extract::<usize>(py)?;
279262
DaftResult::Ok(pb_id)
280263
})?;

0 commit comments

Comments
 (0)