Repository navigation
fix(open): chain the byte streams of several files like cat - #19341
Conversation
|
We don't want to collect files, we want to stream them. If you want to collect you should |
|
fair, makes sense to keep it streaming. would you take it if each file stayed its own stream instead of being merged into one, or are the 8k chunks just the expected behaviour here? |
The 8k chunks are the bug from #10027, not behavior we want. They're read-buffer boundaries with nothing to do with the content, and they break anything downstream that looks at the text. Two copies of a 2000-line file: > open lines.txt lines.txt | lines | length
4004
> open lines.txt lines.txt | lines | where $it !~ "^line \d+$"
╭───┬──────────╮
│ 0 │ li │
│ 1 │ ne 923 │
│ 2 │ l │
│ 3 │ ine 1750 │
│ 4 │ li │
│ 5 │ ne 923 │
│ 6 │ l │
│ 7 │ ine 1750 │
╰───┴──────────╯A list where each file is its own stream can't be built. List items are So |
|
where are we at on this? |
|
hey @fdncred ill get on that on weekend, sorry, completely forgot about it |
|
pushed, several files are chained into one byte stream now like cat, so |
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
Chaining fixes the 8 KiB chunks. On the two-file cases str length gives 30000, and lines gives 4000 lines with no fragments. With very many files the nested Chain gets quadratically slow and then overflows the stack, and a converter's typed byte stream loses its type.
Findings: 1
Open (4)
Notes from my clanker, checked on fe3bbd7. Built the branch in debug and release. Ran cargo test -p nu-command --test tests -- commands::open (131 passed), plus clippy with CI's flags, cargo fmt --all --check and typos, all clean. Each case also ran on the branch binary and on main 1dc849d. CI hasn't run on this head yet.
…m type Nesting one Chain per file made reads quadratic and overflowed the stack with many files, so the readers are now read one after another from a flat list. When every stream has the same type it is kept, otherwise it falls back to Unknown. Also adds an example for opening several files.
|
thanks, applied all four. the readers are a flat list now so nothing nests per file, the stream type is kept when all files share it (added a test with your |
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
All four earlier threads are fixed on 4e2cdc6 and resolved. One thing left: every file's read buffer is allocated before the first read, so memory grows by about 8 KiB per file.
Findings: 0
Notes from my clanker, checked on 4e2cdc6. Built the branch in debug and release. cargo test -p nu-command --test tests -- commands::open gave 132 passed, clippy with CI's flags and cargo fmt --all --check are clean, and CI is green. Peak memory came from /usr/bin/time -l on release builds of main 1dc849d, the branch and the lazy-reader trial. I ran my probe scripts on the trial but not cargo test.
Collecting every reader up front allocated each file's read buffer before anything was read. The byte streams are kept instead and turned into readers one at a time.
|
makes sense, done. it keeps the streams now and only turns the next one into a reader when the previous one runs out, so theres one buffer alive at a time. open tests still pass, i didnt redo the memory numbers here |
|
Thanks |



Description
open a.bin b.binflattened every file's byte stream into the output, so each file came out as 8192 byte chunks that had nothing to do with the content ([8192, 1808, 8192, 8192, 3616]for a 10000 and a 20000 byte file), which brokelines,decodeand anything else looking at the text. when every file stays a byte stream (--rawor nofromconverter) they are now chained into one byte stream likecat, read one after another from a flat list so many files dont nest readers. if all streams share a type it is kept, otherwise it falls back toUnknown. tables from converters are still flattened together like before. tests:open_multiple_files_chains_byte_streamsandopen_multiple_files_keeps_converter_stream_type.User-facing changes (Release notes)
openwith several files that stay byte streams now returns one byte stream, likecat, instead of 8 KiB chunks:open a.txt b.txt | str lengthgives the combined length, and| lengthno longer counts chunksopen a.txt b.txt | get 0doesnt work anymore since the result isnt a listcat, a file without a trailing newline runs into the next file's first line withlinesfor one value per file use
[a.txt b.txt] | each { open $in }.Additional notes
fixes #10027