Skip to content

JPEG : Optimize ScaledCopyTo and Block8x8F for common scale factors#3115

Open
JimBobSquarePants wants to merge 4 commits intomainfrom
js/jpeg-decode-resize-opts
Open

JPEG : Optimize ScaledCopyTo and Block8x8F for common scale factors#3115
JimBobSquarePants wants to merge 4 commits intomainfrom
js/jpeg-decode-resize-opts

Conversation

@JimBobSquarePants
Copy link
Copy Markdown
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Improves the performance of the JPEG block scaling and normalization logic in Block8x8F. The main changes are the addition of specialized, loopless scaling routines for common scale factors and the refactoring of the SIMD normalization methods to clarify their responsibilities and remove unnecessary rounding. Fixes #1782

The rounding removal affected our test comparisons far less than I expected but yielded clear visible improvements in some images. For example the replaced image here had blocking that was visible to my eye.

image

Benchmarks

Performance is sitting pretty following the changes. The playground benchmark has us sitting firmly in 2nd and 3rd place.

BenchmarkDotNet v0.15.8, Windows 11 (10.0.26200.8117/25H2/2025Update/HudsonValley2)
AMD RYZEN AI MAX+ 395 w/ Radeon 8060S 3.00GHz, 1 CPU, 32 logical and 16 physical cores
.NET SDK 10.0.202
  [Host]   : .NET 10.0.6 (10.0.6, 10.0.626.17701), X64 RyuJIT x86-64-v4
  ShortRun : .NET 10.0.6 (10.0.6, 10.0.626.17701), X64 RyuJIT x86-64-v4

Job=ShortRun  IterationCount=5  LaunchCount=1
WarmupCount=5
Method Mean Error StdDev Ratio
'MagicScaler Load, Resize, Save' 33.30 ms 1.865 ms 0.289 ms 0.17
'ImageSharp TD Load, Resize, Save' 39.29 ms 2.155 ms 0.560 ms 0.20
'ImageSharp Load, Resize, Save' 59.90 ms 1.506 ms 0.233 ms 0.31
'NetVips Load, Resize, Save' 62.45 ms 3.032 ms 0.787 ms 0.32
'SkiaSharp Load, Resize, Save' 77.42 ms 2.112 ms 0.548 ms 0.40
'ImageFree Load, Resize, Save' 133.77 ms 0.498 ms 0.077 ms 0.70
'ImageFlow Load, Resize, Save' 139.14 ms 4.920 ms 1.278 ms 0.72
'System.Drawing Load, Resize, Save' 192.39 ms 2.858 ms 0.442 ms 1.00
'ImageMagick Load, Resize, Save' 207.08 ms 9.209 ms 1.425 ms 1.08

@JimBobSquarePants JimBobSquarePants changed the title Optimize ScaledCopyTo and Block8x8F for common scale factors JPEG : Optimize ScaledCopyTo and Block8x8F for common scale factors Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Post IDCT rounding needs to go - it induces noise & generational loss and takes extra time to compute

1 participant