Skip to content

image/png: use branch-free abs function in abs8 #63492

@haruyama480

Description

@haruyama480

This is not a bug issue, but propose of optimization.
So, I change subjects of pr-templates.

overview

In the past CL, a branch-free abs was applied to optimize Paeth filters.
https://codereview.appspot.com/117290043

Applying this to abs8 in write.go also improved the latency of BenchmarkEncodeRGBA by 38%.

result

goos: darwin
goarch: arm64
pkg: image/png
                            │   old.txt   │               new.txt               │
                            │   sec/op    │   sec/op     vs base                │
Paeth-10                      2.536n ± 1%   2.534n ± 0%        ~ (p=0.378 n=10)
DecodeGray-10                 354.2µ ± 1%   354.5µ ± 0%        ~ (p=0.353 n=10)
DecodeNRGBAGradient-10        1.510m ± 0%   1.513m ± 0%   +0.16% (p=0.043 n=10)
DecodeNRGBAOpaque-10          1.212m ± 0%   1.215m ± 0%   +0.28% (p=0.011 n=10)
DecodePaletted-10             190.3µ ± 2%   190.2µ ± 2%        ~ (p=0.684 n=10)
DecodeRGB-10                  1.085m ± 1%   1.085m ± 0%        ~ (p=0.912 n=10)
DecodeInterlacing-10          1.393m ± 0%   1.391m ± 0%        ~ (p=0.052 n=10)
EncodeGray-10                 1.178m ± 0%   1.127m ± 0%   -4.39% (p=0.000 n=10)
EncodeGrayWithBufferPool-10   1.104m ± 0%   1.052m ± 0%   -4.65% (p=0.000 n=10)
EncodeNRGBOpaque-10           3.566m ± 0%   3.449m ± 1%   -3.29% (p=0.000 n=10)
EncodeNRGBA-10                3.891m ± 1%   3.727m ± 0%   -4.23% (p=0.000 n=10)
EncodePaletted-10             1.541m ± 0%   1.535m ± 0%   -0.39% (p=0.011 n=10)
EncodeRGBOpaque-10            3.567m ± 0%   3.445m ± 0%   -3.41% (p=0.000 n=10)
EncodeRGBA-10                 24.58m ± 0%   15.25m ± 1%  -37.97% (p=0.000 n=10)
geomean                       616.8µ        587.4µ        -4.75%

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions