abonander / buf_redux

A drop-in replacement for Rust's std::io::BufReader, with extra features
Apache License 2.0
38 stars 16 forks source link

more efficient seeks #9

Open dignifiedquire opened 5 years ago

dignifiedquire commented 5 years ago

I am looking into using seeking quite a bit and was wondering if it was possible to upgrade the seeking implementation like it is done here: https://github.com/gcarq/seek_bufread

the stdlib will hopefully get sth similar eventually, ref: https://github.com/rust-lang/rust/issues/31100

abonander commented 5 years ago

Are you looking for something like the unstable BufReader::seek_relative()? https://doc.rust-lang.org/nightly/std/io/struct.BufReader.html#method.seek_relative

dignifiedquire commented 5 years ago

My code needs to be able to do both relative and from start seeks, but they likely will be inside the current buffer, due to the way they are called, so seek_relative is unfortunately not enough for me.

On a related note, in the linked tracking issue https://github.com/rust-lang/rust/issues/31100 it seems that the sentiment is, to actually change the behaviour of seek, instead of stabilising seek_relative.

https://github.com/rust-lang/rust/issues/31100#issuecomment-394134413 On 16. Nov 2018, 22:23 +0100, Austin Bonander notifications@github.com, wrote:

Are you looking for something like the unstable BufReader::seek_relative()? https://doc.rust-lang.org/nightly/std/io/struct.BufReader.html#method.seek_relative — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

abonander commented 5 years ago

So you want the reader to store the absolute offset, to the best of its knowledge, and optimize for when seeks fall within the buffer.

That's not unreasonable, but I think to avoid surprises this should be implemented as a wrapper type or at the very least a separate method. For cases where the user is expecting the data at a local offset to change in the underlying reader, this optimization would cause seeks to yield stale data. I'd rather keep the stdlib semantics for BufReader unless those change.