Require BufRead + Seek bound for decoding #558
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.
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
: