forked from extern/nushell
table
: Check stream timeout on every item (#7509)
`table` handles slow `ListStream`s in a special way: every 100 items, it checks whether 1 second has elapsed since the last table page, and if so it outputs a new page with all the items in its buffer. **I would like to remove the "every 100 items" condition and always output whatever we have if a second has elapsed.** I think this will be a better user experience for very slow streams. As a motivating example, imagine tailing a log file and doing some string parsing/projection on each line. The user will be really annoyed if they have to wait for 100 lines to be written to the log before seeing new results! I did some quick performance measurements with Criterion, and the elapsed-time check takes about 16ns on my machine (Linux, 12900k). I think the performance impact of checking that for every item will be negligible.
This commit is contained in:
parent
3a2c7900d6
commit
22c50185b5
@ -19,7 +19,6 @@ use terminal_size::{Height, Width};
|
|||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
const STREAM_PAGE_SIZE: usize = 1000;
|
const STREAM_PAGE_SIZE: usize = 1000;
|
||||||
const STREAM_TIMEOUT_CHECK_INTERVAL: usize = 100;
|
|
||||||
const INDEX_COLUMN_NAME: &str = "index";
|
const INDEX_COLUMN_NAME: &str = "index";
|
||||||
|
|
||||||
type NuText = (String, TextStyle);
|
type NuText = (String, TextStyle);
|
||||||
@ -1685,13 +1684,9 @@ impl Iterator for PagingTableCreator {
|
|||||||
batch.push(item);
|
batch.push(item);
|
||||||
idx += 1;
|
idx += 1;
|
||||||
|
|
||||||
if idx % STREAM_TIMEOUT_CHECK_INTERVAL == 0 {
|
// If we've been buffering over a second, go ahead and send out what we have so far
|
||||||
let end_time = Instant::now();
|
if (Instant::now() - start_time).as_secs() >= 1 {
|
||||||
|
break;
|
||||||
// If we've been buffering over a second, go ahead and send out what we have so far
|
|
||||||
if (end_time - start_time).as_secs() >= 1 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if idx == STREAM_PAGE_SIZE {
|
if idx == STREAM_PAGE_SIZE {
|
||||||
|
Loading…
Reference in New Issue
Block a user