Repository navigation
cut: bound memory usage for streamable selections and improve the perf (+23%) - #15094
Conversation
Merging this PR will improve performance by 23.3%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
|
please fix clippy and cspell |
|
GNU testsuite comparison: |
Please remove from |
|
@mattsu2020 please convert to draft until it is ready |
bcbf274 to
aaa335a
Compare
|
CICD / Code Coverage (ubuntu-latest, unix) (pull_request) failure tracked by #15100. |
|
@mattsu2020 when it is ready, please drop merge commits and then rebase for a clean history |
| out_delim: &[u8], | ||
| explicit_delim: bool, | ||
| /// Process records in fixed-size chunks without retaining their contents. | ||
| fn for_record_chunks<R: Read>( |
There was a problem hiding this comment.
seems like a too generic function name, it doesn't say that a record is split into pieces
|
sorry but it needs to be rebased |
| ) -> UResult<()> { | ||
| let encoding = locale_encoding(); | ||
| if encoding == Encoding::SingleByte || !(by_char || opts.suppress_split) { | ||
| if ranges.is_empty() || encoding == Encoding::SingleByte || !(by_char || opts.suppress_split) { |
There was a problem hiding this comment.
when can ranges be empty here? --complement -c 1-? please add a test for it
| ) -> UResult<()> { | ||
| let encoding = locale_encoding(); | ||
| if encoding == Encoding::SingleByte || !(by_char || opts.suppress_split) { | ||
| if ranges.is_empty() || encoding == Encoding::SingleByte || !(by_char || opts.suppress_split) { |
There was a problem hiding this comment.
when can ranges be empty here? --complement -c 1-? please add a test for it
|
|
||
| // All supported encodings use at most four bytes per character. Once | ||
| // this prefix is present, later bytes cannot affect a finite selection. | ||
| if let Some(limit) = ranges.last().and_then(|r| r.high.checked_mul(4)) { |
There was a problem hiding this comment.
open-ended ranges like -c 2- still keep the whole record in memory in UTF-8, is it expected?
if yes, please say it in the PR description
| delimiter: u8, | ||
| ) -> UResult<()> { | ||
| let newline = opts.line_ending.into(); | ||
| let only_delimited = opts.field_opts.as_ref().unwrap().only_delimited; |
There was a problem hiding this comment.
cut_fields already unwrapped field_opts, could you please pass only_delimited as a parameter instead?
| let buffer_first = first_selected == only_delimited; | ||
| let delimiter_bytes = [delimiter]; | ||
| let matcher = ExactMatcher::new(&delimiter_bytes); | ||
| let mut first = Vec::new(); |
There was a problem hiding this comment.
this is a lot of mut, often a sign of potential refactor
54a1d8b to
9eab958
Compare
|
Binary size comparison: |
9eab958 to
931d159
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
cut buffers entire records in several modes, causing memory to grow without bound on input without newlines. Stream byte selections and single-byte fields, and retain only the required prefix for finite character selections. Add regression tests for chunk boundaries and long records under a memory limit.
Closes #13990
Validation: 64 cut integration tests and 22 unit tests pass on macOS. The Linux memory-limit regression test has not been run locally.
Limitation: an open-ended character range such as
-c 2-in a multi-byte locale still keeps the whole record in memory, since there is no upper bound on the prefix to retain.