%read
in chunks for lseek()able files.
#107
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a performance optimization that's normally insignificant; occasionally good, in tight
%read
loops; and very rarely negative, when those tight%read
loops work on a file with mostly zero-to-one character lines. Generally the performance improvement increases as line lengths increase, which shouldn't be a surprise. Files with pretty short lines, like/usr/share/dict/words
, see a measurable improvement with tight%read
loops, though.In theory, it seems to me the overhead of the extra
lseek()
calls (which are the source of the negative effects, where they appear) could be reduced by caching the seekability of fds. Maybe just one such value, assuming performance-sensitive calls to%read
are typically done repeatedly in a loop (and on a single fd).This introduces an awkward performance asymmetry, sadly, between the cases of
cat foo | the_script
andthe_script < foo
, since stdin in the former case is non-seekable from a pipe, while in the latter case it's seekable.I'm not married to this proposal. Just wanted to put it out there. I'm not very good at speedy code so there's very possibly a better way to do this than I've got here :)