Reduce overhead reading byte/sbyte arrays from IndexedReader #405
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.
Traces gathered over the test suite show:
IndexedReader.GetByte(int)
IndexedReader.GetSByte(int)
Looking at the main callers shows loops in
TiffReader
that call these methods in loops. This approach accrues overhead per-byte due to bounds checking and virtual dispatch.Instead, use the
Span<byte>
overload ofGetBytes
that performs the bounds checking once, then copies data in a single call.It may be possible to give a similar treatment to the handling of other TIFF format codes, though they're not currently showing up on traces and would be more complex to implement due to byte-ordering issues (
byte
andsbyte
being immune from those).