-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require BufRead + Seek bound for decoding #558
base: master
Are you sure you want to change the base?
Conversation
The But the blanket The PNG format has been carefully designed to not require seeking, so Could the fn rewind_animation(&mut self) where R: Seek The decoder could support skipping of chunks better, but that doesn't require |
The problem with skipping chunks is knowing what to skip. If the user later asks for a chunk and you skipped it earlier, it is already too late. We've already picked up a couple ugly At the moment, the use-case for |
I think it'd be reasonable to have user specify what chunks they're interested in before parsing. Applications either just want pixels, and don't care about the metadata, or can list chunks they have support for, or just want all chunks to roundtrip the file. This doesn't have to be a bunch of bespoke methods and booleans. It can be a list of chunk names and all/none special case. |
8064e22
to
310df06
Compare
The addition of a
BufRead
bound was initially proposed in #427. At the time, the main image crate did not require that bound and the performance implications were uncertain. We've now done a major release of the image crate with suitable API updates, and some early experiments have shown that refactoring taking advantage ofBufRead
can yield modest performance improvement. At the moment, the only actual change related toBufRead
is that we directly use the provided reader rather than wrapping in aBufReader
.Seek
isn't used yet, but it will enable possible future improvements like rewinding the decoder when an animation finishes or delaying the reading of large EXIF / ICC / text chunks unless or until the user queries them.Overall the performance difference on real-world images seems to be in the noise, but there's a ~10% improvement on the synthetic noncompressed benchmarks.
The main user-facing impact from this change is some changes when constructing a decoder...
If you pass a
File
object, wrap it in aBufReader
:If you have a byte slice, wrap it in a
Cursor
: