Skip to content
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

Pass image data directly to ZlibStream, bypassing ChunkState::raw_bytes #424

Merged
merged 6 commits into from
Nov 14, 2023

Conversation

anforowicz
Copy link
Contributor

PTAL?

This is a part of the "Revisiting copy avoidance" part of the discussion at #416 (comment).

This helps with unifying how image data from IDAT and fdAT is handled.
This unification is a prerequisite for the follow-up commit where we
will avoid temporarily copying compressed image data into
`current_chunk.raw_bytes`.
…bytes`.

Before these changes we would store all image data in
`ChunkState::raw_bytes` before attempting to decompress them via
`ZlibStream`.  This is undesirable for performance, because 1) it copies
data unnecessarily into and out of `raw_bytes` and 2) by the time we
have stored all the image data, the start of it may be already gone from
the L1 cache.

After these changes, the image data is passed directly into
`ZlibStream`.

This commit is part of a bigger set of changes that avoids copying image
pixels across different buffers.  This commit alone gives notable
although relatively small performance improvements, but the real
motivation here is to make progress toward merging the bigger set of
changes and realizing their performance gains.  For more information
see the "Revisiting copy avoidance" part of the discussion at
image-rs#416 (comment)

Performance impact of this commit (2 measurement attempts):

* `decode/8x8-noncompressed.png` - runtime improved by 9.18% - 9.99%
* `128x128-noncompressed.png` - runtime improved by 7.89% - 8.51%
* `decode/Transparency.png` - runtime improved by 1.92% - 2.69%

No impact on the other test inputs:

* `decode/kodim02.png` - change within noise threshold (same result when
  rerun)
* `decode/kodim07.png` - no change detected (p = 0.06 or 0.17 > 0.05)
* `decode/kodim17.png` - runtime improved by 1.75%
  (change within noise threshold when rerun)
* `decode/kodim23.png` - runtime regressed by 2.15%
  (no change detected when rerun - p = 0.86 > 0.05)
* `Lohengrin_-_Illustrated_Sporting_and_Dramatic_News.png` - change
  within noise threshold (no change detected when rerun - p = 0.14 >
  0.05)
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.

Left a comment about fdAT handling, but otherwise this looks like a good improvement to me

src/decoder/stream.rs Outdated Show resolved Hide resolved
The move will help with follow-up work, where we want to use generated
PNGs in unit tests of `src/decoder/stream.rs`.
src/test_utils.rs Outdated Show resolved Hide resolved
src/decoder/stream.rs Outdated Show resolved Hide resolved
@fintelia fintelia merged commit 94ef816 into image-rs:master Nov 14, 2023
19 checks passed
@fintelia
Copy link
Contributor

Thanks!

@anforowicz anforowicz deleted the idat-straight-to-zlibstream branch November 15, 2023 00:36
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.

2 participants