Speed up decoder pixel-buffer conversion in decode.rs - #164
Open
nikosavola wants to merge 1 commit into
Open
Conversation
`pixels_to_bytes` (the non-narrowing path, used for I;16/F modes) pushed output bytes one at a time in a loop. Replace the Uint16 and Float arms with a single bulk `bytemuck::cast_slice reinterpret`. Float16 stays a per-element loop (half::f16 isn't asserted Pod/Zeroable here) but is now pre-sized with with_capacity. `pixels_to_bytes_8bit`'s Uint16 arm does a lossy >> 8 narrowing downsample, not a reinterpret, so it intentionally keeps its per-element loop. Only added reserve() there for fewer reallocations. Added unit tests asserting the bulk-cast output is byte-identical to the old per-element construction (including empty-vector inputs), that the Float16 upcast-and-reinterpret path is correct, and that the >> 8 narrowing still behaves correctly.
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.
pixels_to_bytes(the non-narrowing path, used for I;16/F modes) pushed output bytes one at a time in a loop. Replace the Uint16 and Float arms with a single bulkbytemuck::cast_slice reinterpret. Float16 stays a per-element loop (half::f16 isn't asserted Pod/Zeroable here) but is now pre-sized with with_capacity.pixels_to_bytes_8bit's Uint16 arm does a lossy >> 8 narrowing downsample, not a reinterpret, so it intentionally keeps its per-element loop. Only added reserve() there for fewer reallocations.Added unit tests asserting the bulk-cast output is byte-identical to the old per-element construction (including empty-vector inputs), that the Float16 upcast-and-reinterpret path is correct, and that the >> 8 narrowing still behaves correctly.
Note that tests fail until the Cargo.toml change from #163 is merged.