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

Precompute fixed huffman tables #39

Merged
merged 4 commits into from
Nov 30, 2024
Merged

Conversation

fintelia
Copy link
Contributor

@fintelia fintelia commented Nov 30, 2024

This PR switches to using precomputed decoding tables for fixed huffman blocks. Because fixed blocks have all literal/length symbols between 7-9 bits, a 12-bit decoding table is actually just a 9-bit decoding table repeated 8 times. Similarly the distance codes are all 5-bits so 16 repetitions of a 5-bit table are used.

Also switched the decoding tables to use Box instead of raw arrays.

I tried other options to shrink the size of decoding tables for fixed blocks, but having two code paths depending on table size was slower. Making the decoding tables Vecs rather than boxed slices (so they didn't have to be zero-initialized for the fixed-block case) also didn't help performance.

@fintelia fintelia merged commit 6710039 into image-rs:main Nov 30, 2024
10 checks passed
@fintelia fintelia deleted the precompute-fixed branch November 30, 2024 20:39
@fintelia
Copy link
Contributor Author

Incidentally, zlib has analogous decoding tables hard-coded in its source code as well: https://github.com/madler/zlib/blob/ef24c4c7502169f016dcd2a26923dbaf3216748c/inffixed.h

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.

1 participant