New issue
Advanced search Search tips

Issue 706134 link

Starred by 1 user

Issue metadata

Status: Verified
Owner:
Closed: Feb 2018
Cc:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Feature

Blocking:
issue 709707



Sign in to add a comment

Optimize png_do_expand_palette

Project Member Reported by richard....@arm.com, Mar 28 2017

Issue description

Loading large PNG files using palettes could be made faster using SIMD instructions.
 
Owner: cavalcantii@chromium.org
Status: Started (was: Unconfirmed)
Description: Show this description
Palette optimization seems to be commonly used by PNG optimizers (e.g. http://compresspng.com/).

Comment 4 by richard....@arm.com, Mar 28 2017

with_patch.png
218 KB View Download
without_patch.png
224 KB View Download

Comment 5 by richard....@arm.com, Mar 28 2017

with_patch_trace.html.gz
1.3 MB Download
without_patch_trace.html.gz
1.5 MB Download

Comment 6 by richard....@arm.com, Mar 28 2017

I generated these traces with the attached image, run through a third-party PNG optimizer, with additional tracing in PNGImageReader::decode. It's also possible to see the effect of the optimization with the ImageFrameGenerator::decode event. Using this event, I've benchmarked a number of versions of the patch at https://codereview.chromium.org/2771903002/ and seen a 10-30% improvement in decode times, depending on the ARM Chromebook in use. 

Image originally sourced from https://commons.wikimedia.org/wiki/File:ZebraHighRes.png


ZebraPallete.png
852 KB View Download
Blockedon: 687631
Labels: -OS-Linux -Pri-2 OS-Android Pri-3
Cc: msarett@chromium.org fmalita@chromium.org

Comment 9 by msar...@google.com, Mar 28 2017

This is cool!

Would be a really interesting change to consider in the context of SkPngCodec.  SkPngCodec is used in Android and will eventually be used in Chrome ( crbug.com/702860 ).

SkPngCodec tells libpng "just give us the indices", so the table lookups can be handled outside of libpng.  That we can be fast without needing to upstream anything.

But the Skia implementation is not clever enough for vectorized table lookups...  Can we bring these optimizations to Skia?
https://cs.chromium.org/chromium/src/third_party/skia/src/codec/SkSwizzler.cpp?l=271

See here for an example of how to hook opt code into the swizzler.
https://cs.chromium.org/chromium/src/third_party/skia/src/codec/SkSwizzler.cpp?l=450
@matt

From a quick look in the Skia code you pointed, I think it should be doable to make the table lookups faster on ARM.

I would say we could bring this optimizations to Skia as soon we are able to upstream the current optimizations (adler32, inflate_fast and palette).

All that is blocked on upgrading the zlib in Chromium, which is WIP (Work In Progress).

Blockedon: -687631
Blocking: 709707
Cc: -msarett@chromium.org scroggo@chromium.org
Project Member

Comment 13 by bugdroid1@chromium.org, Oct 27 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/f0dfc858de0d129a4e8a013ae9f870b710fc2d80

commit f0dfc858de0d129a4e8a013ae9f870b710fc2d80
Author: Richard Townsend <Richard.Townsend@arm.com>
Date: Fri Oct 27 12:47:06 2017

Add a palettized PNG decoding case

Sites often use custom palettes to optimize PNG images using
space-saving (but accurate) indexed colours.

Bug:  706134 
Change-Id: Ie47296fb3d8552a884b86af1c9e3b92130011fd7
Reviewed-on: https://chromium-review.googlesource.com/739391
Reviewed-by: Ned Nguyen <nednguyen@google.com>
Reviewed-by: Chris Blume <cblume@chromium.org>
Commit-Queue: Chris Blume <cblume@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512159}
[add] https://crrev.com/f0dfc858de0d129a4e8a013ae9f870b710fc2d80/third_party/WebKit/PerformanceTests/ImageDecoder/decode-png-palette.html
[add] https://crrev.com/f0dfc858de0d129a4e8a013ae9f870b710fc2d80/third_party/WebKit/PerformanceTests/ImageDecoder/resources/palette.png

Project Member

Comment 14 by bugdroid1@chromium.org, Nov 14 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/2d0a36dac3c24e26f2e9a7537290ff321c0f36d7

commit 2d0a36dac3c24e26f2e9a7537290ff321c0f36d7
Author: Richard Townsend <Richard.Townsend@arm.com>
Date: Tue Nov 14 21:53:59 2017

Add another palettized PNG decode case

Sites often use lossy PNG compression techniques à la pngquant to reduce
download size. droids.palette.png is an image prepared with this tool.
This image doesn't have any transparency, so it uses a different libpng
decode path.

Bug:  706134 
Change-Id: I27844651b1c9324b3186c977531eba7d1ad55dea
Reviewed-on: https://chromium-review.googlesource.com/761516
Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org>
Reviewed-by: Chris Blume <cblume@chromium.org>
Reviewed-by: Ned Nguyen <nednguyen@google.com>
Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516443}
[add] https://crrev.com/2d0a36dac3c24e26f2e9a7537290ff321c0f36d7/third_party/WebKit/PerformanceTests/ImageDecoder/decode-png-palette-opaque.html
[modify] https://crrev.com/2d0a36dac3c24e26f2e9a7537290ff321c0f36d7/third_party/WebKit/PerformanceTests/ImageDecoder/decode-png-palette.html
[add] https://crrev.com/2d0a36dac3c24e26f2e9a7537290ff321c0f36d7/third_party/WebKit/PerformanceTests/ImageDecoder/resources/droids.palette.png

https://chromium-review.googlesource.com/c/chromium/src/+/817116 (subject to review) optimizes decoding for RGBA/RGB PNGs which use an 8-bit palette. Attached to this comment are some spreadsheets which detail the results:

* Improvement on PNG140 (average of 5% improvement on A72 and 23% on A53 for RGBA/RGB images which use an 8-bit palette).
* Performance is not seriously impacted for cases in the rest of PNG140, on a collection of Google Doodles, and on the Kodak PNG corpus which don't use a palette.
PNG Palette - Regressions Check.ods
114 KB Download
PNG Palette - PNG140 Analysis.ods
90.7 KB Download
Cc: mtklein@chromium.org
Spreadsheet of various alternate ways of doing things to accompany patchset #5.
PNG Palette - PNG140 Analysis - Patchset #5 Suggestions.ods
76.5 KB Download
Slightly updated spreadsheet.
PNG Palette - PNG140 Analysis - Patchset #5 Suggestions.ods
88.2 KB Download
Owner: richard....@arm.com
Project Member

Comment 21 by bugdroid1@chromium.org, Jan 16 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/c4811af6d72836d44a3630beecebb0ff55875ab1

commit c4811af6d72836d44a3630beecebb0ff55875ab1
Author: Richard Townsend <Richard.Townsend@arm.com>
Date: Tue Jan 16 18:46:42 2018

libpng: Optimize png_do_expand_palette with NEON.

ARM-specific optimization processes 8 or 4 pixels at once.

* Without transparency: 22% performance gain on the A53 little core.
* With transparency: 10% improvement on a big A72 core, 24% on little.

(Numbers from image_decode_bench with PNG140 on the elm chromebook).

Bug:  706134 
Change-Id: I7b4a93d72a0afa2823f3bf9ff5f798b88c843e54
Reviewed-on: https://chromium-review.googlesource.com/817116
Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Reviewed-by: Leon Scroggins <scroggo@chromium.org>
Reviewed-by: Chris Blume <cblume@chromium.org>
Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#529473}
[modify] https://crrev.com/c4811af6d72836d44a3630beecebb0ff55875ab1/third_party/libpng/BUILD.gn
[add] https://crrev.com/c4811af6d72836d44a3630beecebb0ff55875ab1/third_party/libpng/arm/palette_neon_intrinsics.c
[add] https://crrev.com/c4811af6d72836d44a3630beecebb0ff55875ab1/third_party/libpng/patches/0000-plte.patch
[add] https://crrev.com/c4811af6d72836d44a3630beecebb0ff55875ab1/third_party/libpng/patches/README
[modify] https://crrev.com/c4811af6d72836d44a3630beecebb0ff55875ab1/third_party/libpng/pngpriv.h
[modify] https://crrev.com/c4811af6d72836d44a3630beecebb0ff55875ab1/third_party/libpng/pngrtran.c
[modify] https://crrev.com/c4811af6d72836d44a3630beecebb0ff55875ab1/third_party/libpng/pngstruct.h
[modify] https://crrev.com/c4811af6d72836d44a3630beecebb0ff55875ab1/third_party/libpng/pngwrite.c

Project Member

Comment 22 by bugdroid1@chromium.org, Jan 16 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/20a18ebc02429a40e4bc33fa28c4de29a39b609c

commit 20a18ebc02429a40e4bc33fa28c4de29a39b609c
Author: Jonathan Ross <jonross@chromium.org>
Date: Tue Jan 16 19:11:04 2018

Revert "libpng: Optimize png_do_expand_palette with NEON."

This reverts commit c4811af6d72836d44a3630beecebb0ff55875ab1.

Reason for revert: This is failing to compile on ios-device-xcode-clang bot.

https://uberchromegw.corp.google.com/i/chromium.mac/builders/ios-device-xcode-clang/builds/50225

Original change's description:
> libpng: Optimize png_do_expand_palette with NEON.
> 
> ARM-specific optimization processes 8 or 4 pixels at once.
> 
> * Without transparency: 22% performance gain on the A53 little core.
> * With transparency: 10% improvement on a big A72 core, 24% on little.
> 
> (Numbers from image_decode_bench with PNG140 on the elm chromebook).
> 
> Bug:  706134 
> Change-Id: I7b4a93d72a0afa2823f3bf9ff5f798b88c843e54
> Reviewed-on: https://chromium-review.googlesource.com/817116
> Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org>
> Reviewed-by: Mike Klein <mtklein@chromium.org>
> Reviewed-by: Leon Scroggins <scroggo@chromium.org>
> Reviewed-by: Chris Blume <cblume@chromium.org>
> Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#529473}

TBR=scroggo@chromium.org,cavalcantii@chromium.org,richard.townsend@arm.com,cblume@chromium.org,mtklein@chromium.org

Change-Id: I2cd943e15ceadf4311b1b49a56de00d10684e294
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug:  706134 
Reviewed-on: https://chromium-review.googlesource.com/868770
Reviewed-by: Jonathan Ross <jonross@chromium.org>
Commit-Queue: Jonathan Ross <jonross@chromium.org>
Cr-Commit-Position: refs/heads/master@{#529484}
[modify] https://crrev.com/20a18ebc02429a40e4bc33fa28c4de29a39b609c/third_party/libpng/BUILD.gn
[delete] https://crrev.com/ccd674c83551176374d45eea7a6b0bef07bd2f2e/third_party/libpng/arm/palette_neon_intrinsics.c
[delete] https://crrev.com/ccd674c83551176374d45eea7a6b0bef07bd2f2e/third_party/libpng/patches/0000-plte.patch
[delete] https://crrev.com/ccd674c83551176374d45eea7a6b0bef07bd2f2e/third_party/libpng/patches/README
[modify] https://crrev.com/20a18ebc02429a40e4bc33fa28c4de29a39b609c/third_party/libpng/pngpriv.h
[modify] https://crrev.com/20a18ebc02429a40e4bc33fa28c4de29a39b609c/third_party/libpng/pngrtran.c
[modify] https://crrev.com/20a18ebc02429a40e4bc33fa28c4de29a39b609c/third_party/libpng/pngstruct.h
[modify] https://crrev.com/20a18ebc02429a40e4bc33fa28c4de29a39b609c/third_party/libpng/pngwrite.c

Project Member

Comment 23 by bugdroid1@chromium.org, Jan 16 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/4173576b1600fb51d7166b17009b3a16dcfdddaf

commit 4173576b1600fb51d7166b17009b3a16dcfdddaf
Author: Chris Blume <cblume@chromium.org>
Date: Tue Jan 16 23:48:47 2018

Revert "Revert "libpng: Optimize png_do_expand_palette with NEON.""

This reverts commit 20a18ebc02429a40e4bc33fa28c4de29a39b609c.

Reason for revert: The failing iOS build should be fixed.

Original change's description:
> Revert "libpng: Optimize png_do_expand_palette with NEON."
>
> This reverts commit c4811af6d72836d44a3630beecebb0ff55875ab1.
>
> Reason for revert: This is failing to compile on ios-device-xcode-clang bot.
>
> https://uberchromegw.corp.google.com/i/chromium.mac/builders/ios-device-xcode-clang/builds/50225
>
> Original change's description:
> > libpng: Optimize png_do_expand_palette with NEON.
> >
> > ARM-specific optimization processes 8 or 4 pixels at once.
> >
> > * Without transparency: 22% performance gain on the A53 little core.
> > * With transparency: 10% improvement on a big A72 core, 24% on little.
> >
> > (Numbers from image_decode_bench with PNG140 on the elm chromebook).
> >
> > Bug:  706134 
> > Change-Id: I7b4a93d72a0afa2823f3bf9ff5f798b88c843e54
> > Reviewed-on: https://chromium-review.googlesource.com/817116
> > Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org>
> > Reviewed-by: Mike Klein <mtklein@chromium.org>
> > Reviewed-by: Leon Scroggins <scroggo@chromium.org>
> > Reviewed-by: Chris Blume <cblume@chromium.org>
> > Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#529473}
>
> TBR=scroggo@chromium.org,cavalcantii@chromium.org,richard.townsend@arm.com,cblume@chromium.org,mtklein@chromium.org
>
> Change-Id: I2cd943e15ceadf4311b1b49a56de00d10684e294
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug:  706134 
> Reviewed-on: https://chromium-review.googlesource.com/868770
> Reviewed-by: Jonathan Ross <jonross@chromium.org>
> Commit-Queue: Jonathan Ross <jonross@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#529484}

TBR=scroggo@chromium.org,jonross@chromium.org,cavalcantii@chromium.org,richard.townsend@arm.com,cblume@chromium.org,mtklein@chromium.org

Change-Id: I6baf17d35efbd5c6bc348d4f81264e8e1023be4f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug:  706134 
Reviewed-on: https://chromium-review.googlesource.com/868396
Reviewed-by: Jonathan Ross <jonross@chromium.org>
Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org>
Reviewed-by: Chris Blume <cblume@chromium.org>
Commit-Queue: Chris Blume <cblume@chromium.org>
Cr-Commit-Position: refs/heads/master@{#529521}
[modify] https://crrev.com/4173576b1600fb51d7166b17009b3a16dcfdddaf/third_party/libpng/BUILD.gn
[add] https://crrev.com/4173576b1600fb51d7166b17009b3a16dcfdddaf/third_party/libpng/arm/palette_neon_intrinsics.c
[add] https://crrev.com/4173576b1600fb51d7166b17009b3a16dcfdddaf/third_party/libpng/patches/0000-plte.patch
[add] https://crrev.com/4173576b1600fb51d7166b17009b3a16dcfdddaf/third_party/libpng/patches/README
[modify] https://crrev.com/4173576b1600fb51d7166b17009b3a16dcfdddaf/third_party/libpng/pngpriv.h
[modify] https://crrev.com/4173576b1600fb51d7166b17009b3a16dcfdddaf/third_party/libpng/pngrtran.c
[modify] https://crrev.com/4173576b1600fb51d7166b17009b3a16dcfdddaf/third_party/libpng/pngstruct.h
[modify] https://crrev.com/4173576b1600fb51d7166b17009b3a16dcfdddaf/third_party/libpng/pngwrite.c

This was reverted due to an unrelated bug, but was relanded with https://chromium-review.googlesource.com/902145. This looks to be done. Is there more work planned here or can this bug be closed?
Status: Fixed (was: Started)
No more work is planned for the time being, thanks for all your help! 
Status: Verified (was: Fixed)
For reference, upstream merge request is:
https://github.com/glennrp/libpng/pull/203

Sign in to add a comment