Zig Version
0.12.0-dev.1396+f6de3ec96
Steps to Reproduce and Observed Behavior
The implementation of std.io.Reader.streamUntilDelimiter is essentially:
const byte: u8 = try self.readByte();
if (byte == delimiter) return;
try writer.writeByte(byte);
Which is a reasonable default implementation, but depending on the underlying context, can leave a lot of performance on the table. Specifically, I noticed that reading a large file, line by line, was really slow, despite using a BufferedReader. Implementing streamUntilDelimiter directly on BufferedReader gave anywhere from a 2x to a 15x performance improvement (depending on the input). Here's a benchmark: https://gist.github.com/karlseguin/17cc66cc26f167c1242608bfae73fb06
I made std.io.GenericReader call an underlying streamUntilDelimiter if present: master...karlseguin:zig:buffered_reader_delimiter
But I couldn't figure out how to push this down to std.io.Reader, where I think it would do the most good (various std.io.Reader functions call streamUntilDelimiter).
So, unable to provide a fix, I thought I'd open an issue.
Expected Behavior
It would be nice if the the performance benefits of using a BufferedReader to remain in play even when hidden behind an io.GenericReader or .io.Reader.
Zig Version
0.12.0-dev.1396+f6de3ec96
Steps to Reproduce and Observed Behavior
The implementation of
std.io.Reader.streamUntilDelimiteris essentially:Which is a reasonable default implementation, but depending on the underlying context, can leave a lot of performance on the table. Specifically, I noticed that reading a large file, line by line, was really slow, despite using a BufferedReader. Implementing
streamUntilDelimiterdirectly on BufferedReader gave anywhere from a 2x to a 15x performance improvement (depending on the input). Here's a benchmark: https://gist.github.com/karlseguin/17cc66cc26f167c1242608bfae73fb06I made
std.io.GenericReadercall an underlyingstreamUntilDelimiterif present: master...karlseguin:zig:buffered_reader_delimiterBut I couldn't figure out how to push this down to
std.io.Reader, where I think it would do the most good (variousstd.io.Readerfunctions callstreamUntilDelimiter).So, unable to provide a fix, I thought I'd open an issue.
Expected Behavior
It would be nice if the the performance benefits of using a BufferedReader to remain in play even when hidden behind an
io.GenericReaderor.io.Reader.