Skip to content

Optimize jpeg decoder based on traces.#1303

Merged
JimBobSquarePants merged 3 commits intomasterfrom
js/jpeg-decode-perf
Aug 4, 2020
Merged

Optimize jpeg decoder based on traces.#1303
JimBobSquarePants merged 3 commits intomasterfrom
js/jpeg-decode-perf

Conversation

@JimBobSquarePants
Copy link
Member

@JimBobSquarePants JimBobSquarePants commented Aug 3, 2020

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 matches 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

I ran a trace against the decoder after reading this benchmark here (which we're doing really well with IMO) and thought I'd clean up some low hanging fruit. Shaved a few percent of the decoding benchmarks.

Decode

Adds hardware accelerated rounding to SimdUtils.FastRound.

Before and after performance traces.
jd-before
jd-after

Method TestImage Mean Error StdDev Ratio RatioSD Gen 0 Gen 1 Gen 2 Allocated
'Decode Jpeg - System.Drawing' Jpg/b(...)e.jpg [21] 5.122 ms 1.3978 ms 0.0766 ms 1.00 0.00 - - - 176 B
'Decode Jpeg - ImageSharp' Jpg/b(...)e.jpg [21] 11.991 ms 0.2514 ms 0.0138 ms 2.34 0.03 - - - 15816 B
'Decode Jpeg - System.Drawing' Jpg/b(...)f.jpg [28] 14.943 ms 1.8410 ms 0.1009 ms 1.00 0.00 - - - 176 B
'Decode Jpeg - ImageSharp' Jpg/b(...)f.jpg [28] 29.759 ms 1.5452 ms 0.0847 ms 1.99 0.01 - - - 16824 B
'Decode Jpeg - System.Drawing' Jpg/i(...)e.jpg [43] 388.229 ms 382.8946 ms 20.9877 ms 1.00 0.00 - - - 216 B
'Decode Jpeg - ImageSharp' Jpg/i(...)e.jpg [43] 276.490 ms 195.5104 ms 10.7166 ms 0.71 0.01 - - - 36022368 B

Scan Only
Slight refactor of HuffmanScanBuffer.DecodeHuffman to remove double lookup on slow path. There's now nothing that stands out here.
image

Method Job Runtime TestImage Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
'System.Drawing FULL' Job-HITJFX .NET 4.7.2 Jpg/b(...)e.jpg [21] 5.828 ms 0.9885 ms 0.0542 ms 1.00 46.8750 - - 211566 B
JpegDecoderCore.ParseStream Job-HITJFX .NET 4.7.2 Jpg/b(...)e.jpg [21] 5.833 ms 0.2923 ms 0.0160 ms 1.00 - - - 12416 B
'System.Drawing FULL' Job-WPSKZD .NET Core 2.1 Jpg/b(...)e.jpg [21] 6.018 ms 2.1374 ms 0.1172 ms 1.00 46.8750 - - 210768 B
JpegDecoderCore.ParseStream Job-WPSKZD .NET Core 2.1 Jpg/b(...)e.jpg [21] 4.382 ms 0.9009 ms 0.0494 ms 0.73 - - - 12360 B
'System.Drawing FULL' Job-ZLSNRP .NET Core 3.1 Jpg/b(...)e.jpg [21] 5.714 ms 0.4078 ms 0.0224 ms 1.00 - - - 176 B
JpegDecoderCore.ParseStream Job-ZLSNRP .NET Core 3.1 Jpg/b(...)e.jpg [21] 4.239 ms 1.0943 ms 0.0600 ms 0.74 - - - 12406 B

@JimBobSquarePants JimBobSquarePants requested a review from a team August 3, 2020 20:37
public class DecodeJpegParseStreamOnly
{
[Params(TestImages.Jpeg.Baseline.Jpeg420Exif)]
[Params(TestImages.Jpeg.BenchmarkSuite.Lake_Small444YCbCr)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to match the full decoding benchmark so we can more easily see the difference.

@codecov
Copy link

codecov bot commented Aug 3, 2020

Codecov Report

Merging #1303 into master will decrease coverage by 0.02%.
The diff coverage is 65.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1303      +/-   ##
==========================================
- Coverage   82.79%   82.77%   -0.03%     
==========================================
  Files         689      689              
  Lines       30731    30733       +2     
  Branches     3472     3473       +1     
==========================================
- Hits        25444    25439       -5     
- Misses       4581     4587       +6     
- Partials      706      707       +1     
Flag Coverage Δ
#unittests 82.77% <65.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/ImageSharp/Common/Helpers/SimdUtils.cs 65.90% <36.36%> (-14.58%) ⬇️
...rmats/Jpeg/Components/Decoder/HuffmanScanBuffer.cs 94.73% <100.00%> (-0.07%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 521fae3...1eaaf1a. Read the comment docs.

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a possible issue that is easy to fix, but otherwise looks good. Cool stuff!

Co-authored-by: Anton Firszov <antonfir@gmail.com>
@JimBobSquarePants JimBobSquarePants merged commit a31a541 into master Aug 4, 2020
@JimBobSquarePants JimBobSquarePants deleted the js/jpeg-decode-perf branch August 4, 2020 11:35
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.

3 participants