Read entropy bits a word at a time and decode VLCs by table - #6
Merged
Merged
Conversation
PacketBitReader::read_bits consumed one bit per loop iteration with a bounds-checked byte index, and the three prefix-code decoders (entropy VLCs, CBPHP, and YUV DC/LP patterns) read one bit at a time while linearly searching their code tables and recomputing the maximum code length on every call. Reads of up to 57 bits now take one big-endian 64-bit window load, with the end-of-buffer padding and error construction moved into cold out-of-line paths so the hot path inlines. Every normative prefix table is compiled into an eight-bit lookup; construction is const, so an ambiguous or oversized table fails compilation. Error behavior is unchanged: truncated packets report UnexpectedEnd at the bit where the serial decoder stopped, and unmatched full-length prefixes report InvalidVlc at the code start. Exhaustive tests compare the lookup decoders with the serial search for every 16-bit input, offset, and truncation, and the reader with a bit-serial reference for every width and offset.
The previous commit unintentionally included workspace crate version bumps to 0.2.0 and the matching lockfile entries. Version changes belong to a release PR, so this restores every manifest and Cargo.lock to main.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PacketBitReader::read_bitsconsumed one bit per loop iteration with a bounds-checked byte index. The three prefix-code decoders (entropy VLCs, CBPHP, and YUV DC/LP patterns) also read one bit at a time, linearly searching their code tables and recomputing the maximum code length on every call. Every backend runs this code: CPU, Metal, and CUDA all entropy-decode on the CPU.Reads of up to 57 bits now take one big-endian 64-bit window load. End-of-buffer padding and error construction live in cold out-of-line paths, so the hot path inlines. Every normative prefix table compiles into an eight-bit lookup; construction is
const, so an ambiguous or oversized table fails the build.Error behavior is unchanged. Truncated packets report
UnexpectedEndat the bit where the serial decoder stopped, and unmatched full-length prefixes reportInvalidVlcat the code start. Exhaustive tests compare each lookup decoder with the serial search for every 16-bit input, bit offset, and truncation length. They also compare the reader with a bit-serial reference for every width 0–64 at every offset.Performance. Measured with
jxr-load-bench(in-memory parse + entropy + reconstruction + packing/readback, 3 warmups, 20 iterations) on an M4 Pro, interleaved withmainin the same session. Each value is the lower of two rounds' medians.Gains track the number of entropy-coded bits: high-bit-depth images with many flexbits benefit most.
Validation on an M4 Pro:
cargo fmt --all -- --check;cargo clippy --workspace --all-targets --all-features -- -D warnings;cargo test --workspace --all-features --release(259 passed); T.834/T.835 conformance CPU 517/517 and Metal 517/517.Note: the first commit accidentally picked up workspace crate version bumps to 0.2.0 made in the working tree by something outside this change. The second commit restores every manifest and
Cargo.locktomain, so the net diff is the six entropy files. Please squash-merge.