Skip to content

Speed up saving PNGs by skipping a null transform

Brion Vibber (WMF) requested to merge bvibber/gdk-pixbuf:png-faster into master

Calling png_set_shift to set the number of significant bits of input triggers a transform operation inside libpng which shifts bits around, even if it's a null operation of 8 bits to 8 bits.

I measured this slowdown as about 30% of total saving runtime on a large 7680x2160 screenshot.

In addition, only 8 bits per channel are supported in gdk-pixbuf so this is never actually needed in practice.

Fixes #90 (closed)

Measured improvement using the thumbnail helper (includes load time as well as save time):

before

$ jhbuild run time gdk-pixbuf-thumbnailer ~/src/png/png-squisher/data/dual-4k-sample.png -s 7680 out.png
2.55user 0.04system 0:02.61elapsed 99%CPU (0avgtext+0avgdata 72324maxresident)k

after

$ jhbuild run time gdk-pixbuf-thumbnailer ~/src/png/png-squisher/data/dual-4k-sample.png -s 7680 out.png
2.04user 0.04system 0:02.10elapsed 99%CPU (0avgtext+0avgdata 72236maxresident)k

Merge request reports