Conversation
|
I was testing this locally in combination with #640 and that seems to be important. I was quite defensive with the implementation of the flush behavior and it won't indicate all available data as available but instead performs the same as the usual decoding. This is due to potential internal buffering in This should eliminate the need for a loop as well, the |
|
Turns out the comprehensive fix seemed even harder that the above comment. It goes like this: the currently published code detects whether the IDAT sequence (or fdat) is finished by comparing the next chunk type. For this, it consumes the input stream to fill the bytes that go into Now, this code relies on the caller retrying the So the idea for the fix is now to delay the state change entirely until we can do it without flushing, i.e. until the image data itself has ended. |
|
This seems to improve performance. Some quite significantly. (I think it mostly avoids the weird forced buffer allocations we previously had in the flush call). Alas, it's almost suspicious so no benchmark numbers for now. |
|
I've been thinking about this more, and I believe that the only reason we need to produce more data in Instead, it might be possible to remain in the
Yes, the only time you need to call fdeflate decompression in a loop is if you provide more input data or output space on subsequent iterations. Also for the record: the comment that |
84e0757 to
379dc11
Compare
Avoids forwarding the input stream bytes by consuming further bytes while flushing a sequence of related IDAT-inflate segments. This ensures the decompressor always gets a chance to satisfy the unfilter data demand independent of the input chunk size.
379dc11 to
d4b551f
Compare
Draft to be benchmarked.
Ensure that the buffer is fully flushed before checking for an end-of-file marker via the bool-flag in
fdeflate. We first pass an empty input without setting the flag and repeat the whole flush cycle if that still yielded data. That same data could previously be masked by the missing end-of-file error.See: image-rs/fdeflate#58 (comment)