-
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
Cap buffer sizes via ZlibStream::set_max_total_output
.
#429
Cap buffer sizes via ZlibStream::set_max_total_output
.
#429
Conversation
Hmmm... I guess I need to look into the fuzzing failure. I suspect that IHDR can declare a smaller image size than the real image - I'll try to author a regression test that would do that. |
59fdff1
to
d81d6d7
Compare
This is done now. I am not sure if I need to do something special to kick-off the CI tests again? |
d81d6d7
to
ed2a352
Compare
ed2a352
to
fdd9d84
Compare
@fintelia, can you PTAL? |
Haven't forgotten about this PR. But I've been wanting to finish image-rs/fdeflate#14 first so that we don't have to reserve extra space just to make fdeflate happy Update: |
63c4b67
to
0fb4f46
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fintelia, can you PTAL again?
Thanks for the fdeflate
changes. I've tweaked the PR-under-review to simplify things as allowed by the new fdeflate
behavior.
FWIW, I've re-measured the impact on the non-compressed 8x8 image and still get 20+% improvement.
src/decoder/stream.rs
Outdated
write_rgba8_ihdr_with_width(&mut png, 8); | ||
|
||
// Here we want to test an invalid image where the `IDAT` chunk contains more data | ||
// (data for 8 image) than declared in the `IHDR` chunk (which only describes an 8x8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "8 image" -> "8x256 image"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops. Done.
Left a small comment, but otherwise looks good to me. As a followup I plan to experiment with changing |
Before this commit, `ZlibStream::new` would always allocate and zero out 64kB of data via `out_buffer: vec![0; 2 * CHUNCK_BUFFER_SIZE]`. After this commit, `out_buffer` is capped by the actual size of the decompressed image data. `StreamingDecoder::parse_ihdr` estimates the image size and notifies `ZlibStream` via the new `set_max_total_output` method. Impact on the runtime of the `decode/generated-png:noncompressed-8x8.png` benchmark (3 measurements): * [-24.028% -23.693% -23.460%] (p = 0.00 < 0.05) * [-23.830% -23.480% -23.200%] (p = 0.00 < 0.05) * [-21.259% -20.893% -20.618%] (p = 0.00 < 0.05)
0fb4f46
to
baf5d26
Compare
Ack. Thanks for reviewing!
Thanks for looking into this. Let me try to share a few notes, hoping that it helps (i.e. I am mostly trying to share knowledge and past experience, and definitely not trying to influence the changes one way or another - I don't claim to know which way is "right"). First of all - I note that there are interesting interdependencies between the data:
My early attempts at a similar change can be found in anforowicz@6071020. (Although this is slightly different than what you are considering - here I am avoiding passing
At the same time, removing or replacing the |
PTAL? This results in quite a significant performance improvement for the
noncompressed-8x8.png
benchmark (bigger improvement than #427 and #428 combined - I am surprised).