perf: use padded BitReader fast path in codestream sections#719
Open
hjanuschka wants to merge 1 commit intolibjxl:mainfrom
Open
perf: use padded BitReader fast path in codestream sections#719hjanuschka wants to merge 1 commit intolibjxl:mainfrom
hjanuschka wants to merge 1 commit intolibjxl:mainfrom
Conversation
17 tasks
Benchmark @ 2f1c348Comparing: 7cf3a662 (Base) vs ff54ec06 (PR)
|
veluca93
reviewed
Mar 25, 2026
Member
veluca93
left a comment
There was a problem hiding this comment.
I think I would prefer adding a SectionBuffer type, which wraps a vector while keeping 8 bytes of additional space (and pretending the vector is shorter).
This should significantly simplify the logic.
Also, note that the code as it currently is breaks out-of-bounds detection.
a3453d2 to
0c6045a
Compare
Rework per review feedback: instead of appending 8 zero bytes at dequeue time and tracking real_len separately, SectionBuffer now always allocates len + 8 bytes with zero padding built in. - Add SectionBuffer::ensure_allocated() and bit_reader() methods - Add BitReader::new_with_initial_bits() for padded data with OOB detection based on real data length - I/O writes bounded to buf.len (real data), never touching padding - Incomplete/flush paths still use regular BitReader::new() The zero padding ensures refill() always takes the fast 8-byte LE read path, avoiding refill_slow() for small/tail sections.
0c6045a to
2f1c348
Compare
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.
This adds a padded BitReader constructor and uses it for codestream sections that already have complete buffered data. It keeps incremental/incomplete paths unchanged while avoiding slow refill handling on complete section reads.