You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] while read …; done < file takes time quadratic in the file size, so a 2 MB file hits the 30 s timeout #338
Time grows linearly with the file size. bash reads the 2.07 MB file in 0.18 s.
Actual Behavior
Release build, default 30 s timeout:
File size
Lines
Wall time
Result
262,830 bytes
3,414
0.73 s
ok
518,737 bytes
6,737
2.76 s
ok
1,037,474 bytes
13,474
11.17 s
ok
2,074,948 bytes
26,948
30.00 s
strands-shell: execution timeout exceeded, exit 1
Time goes up about 4 times for each doubling. Controls on the 2.07 MB file: wc -l < /tmp/f; grep -c . /tmp/f takes 0.02 s, and the same loop fed through a pipe (cat /tmp/f | while read -r l; …) takes 0.58 s. One run each.
Additional Context
Found while testing #326; that PR does not change this. read takes one byte per call (src/builtins/read.rs, "Read byte-by-byte to avoid BufReader consuming extra data"). A redirected file reaches the reader as one large chunk, the unread part is kept in a Vec<u8>, and every one-byte read removes its byte from the front of that Vec, which moves all the remaining bytes (src/os.rs:1150-1154 at 2a1495e):
if !remainder.is_empty(){let n = remainder.len().min(buf.remaining());
buf.put_slice(&remainder[..n]);
remainder.drain(..n);returnPoll::Ready(Ok(()));}
A pipe delivers small chunks, which is why the cat … | form is fast.
Possible Solution
Keep the unread part so that taking bytes from the front is cheap: a bytes::Bytes (split_to/advance), a VecDeque<u8>, or a Vec with a read offset.
Activity
test: compare two sizes so the strands-agents#338 timing test does no…