Skip to content

Optimize JPEG coder with flat array and Span<int> - #3

Open
CSharpKun wants to merge 1 commit into
Echostorm44:masterfrom
CSharpKun:perf/jpeg-span-refactor
Open

Optimize JPEG coder with flat array and Span<int>#3
CSharpKun wants to merge 1 commit into
Echostorm44:masterfrom
CSharpKun:perf/jpeg-span-refactor

Conversation

@CSharpKun

Copy link
Copy Markdown

Replaces int[][] Blocks with a single int[] flat array in JpegComponent
All block operations now use Span<int> slices (AsSpan(blockIndex * 64, 64))
Removes per-block allocations and nested loops

The jagged array caused poor cache locality and slow access as well as high pressure on GC.

Performance

Method Before After Change
JPEG Decode 512x512 21.924 ms 19.421 ms -11.4%
Allocated 3.5 MB 3.08 MB -12.8%

All tests passed.

Refs: #2

This commit replaces int[][] Blocks with a single flat int[] array.
All block operations now use Span<int> slices for safe,
allocation-free access.

Refs: Echostorm44#2
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