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

Optimize decoding of fixed huffman blocks #38

Merged
merged 3 commits into from
Nov 29, 2024

Conversation

fintelia
Copy link
Contributor

This PR adds two optimizations to the decoding of fixed huffman blocks:

  • Any fixed blocks with only an EOF symbol are skipped without building a decoding table or running the decoding loop. These should be rare in PNGs, but some encoders may write them due to performing "partial flushes" as they are feeding data into zlib.
  • Consecutive fixed blocks share the same decoding table, so we don't need to rebuild it between blocks.

A possible future optimization would be to cache the fixed block decoding tables in a static variable the first time they are needed. The downside is that it would consume ~16 KB of memory for the rest of the program's lifetime, even if no more decompression was performed.

@fintelia fintelia merged commit 70a8e18 into image-rs:main Nov 29, 2024
10 checks passed
@fintelia fintelia deleted the reuse-table branch November 29, 2024 01:18
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