Skip to content

Conversation

@bushrat011899
Copy link
Contributor

@bushrat011899 bushrat011899 commented May 15, 2025

Objective

Decoder currently wraps any provided reader R in std::io::BufReader, as the decoding process is designed around buffered reads using std::io::BufRead. This can lead to double-buffering issues if the provided reader R already implements std::io::BufRead on its own, leading to possibly lost performance.

Solution

  • Adjusted Decoder<R: Read> into Decoder<R: BufRead>. This is a breaking change users may need to accommodate by replacing Decoder<...> with Decoder<std::io::BufReader<...>> in type signatures.
  • Changed DecodeOptions::read_info to accept an R: BufRead. For migration, you may need to wrap the R parameter in std::io::BufReader::new(...).
  • Changed Decoder::new to accept an R: BufRead. For migration, you may need to wrap the R parameter in std::io::BufReader::new(...).

- Added `DecodeOptions::read_info_buffered`
- Added `Decoder::new_buffered`
- Updated documentation
@bushrat011899
Copy link
Contributor Author

See this comment regarding the CI failure.

@bushrat011899
Copy link
Contributor Author

See #206 for CI failure cause and possible fix.

Copy link
Contributor

@fintelia fintelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is reasonable. The image crate already requires the BufRead bound to decode GIFs in preparation for the possibility that we'd want to make this change.

(There was a slight oversight where GifDecoder::new doesn't require the bound, but calling any methods on the resulting decoder does. Technically that means it would be a breaking change to switch it, but given the limited expected impact, it might be fine to do without a major version bump)

@bushrat011899 bushrat011899 changed the title Add BufRead API to decoder Change Decoder to a BufRead API May 15, 2025
@kornelski
Copy link
Contributor

Related discussion:

image-rs/image#2472

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants