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] >> inside a loop takes time quadratic in the output file's size, so appending 4.6 MB line by line hits the 30 s timeout #388
Time goes up about 3.5 times for each doubling. Control: the same 12,000 lines written through one redirect on the loop (while …; done > /tmp/o) take 0.26 s.
Additional Context
Found while reviewing #378 (the fix for #338). That PR does not change this: its head 3cde1aa gives the same times (0.47 s, 1.62 s, 5.82 s). The two meet in a common script: while read -r l; do echo "$l" >> out; done < in is linear on the read side after #378 and still quadratic on the write side.
Every open with >> reads the whole existing file into a new buffer, adds the new bytes, and writes the whole buffer back when the writer closes. For a VFS file this is src/vfs_kernel.rs:413-430 at 3cde1aa:
letmut buf = if append {let v = vfs_ref.lock().await;
v.read_file(ino).unwrap_or(&[]).to_vec()}else{Vec::new()};whileletSome(chunk) = rx.recv().await{
…
buf.extend_from_slice(&chunk);}letmut v = vfs_ref.lock().await;let _ = v.write_file(ino, buf);
The two direct-bind paths have the same shape (src/vfs_kernel.rs:191-203 and 249-… at dbb6189: tokio::fs::read(&path) / std::fs::read(&path), then a full write). I measured only the VFS path (/tmp/o).
Possible Solution
For an append open, keep only the new bytes and add them to the end of the file when the writer closes: an append method on the VFS for in-memory files, and OpenOptions::append(true) for direct binds. The max_file_size check then needs the current file length rather than the buffer length.
Activity