Skip Menu |

This queue is for tickets about the PDF-API2 CPAN distribution.

Report information
The Basics
Id: 124349
Status: open
Priority: 0/
Queue: PDF-API2

People
Owner: Nobody in particular
Requestors: dusan.vuckovic [...] otrs.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Slow RGBA PNG processing performance
Date: Wed, 7 Feb 2018 10:34:55 +0000
To: bug-PDF-API2 [...] rt.cpan.org
From: Dusan Vuckovic <dusan.vuckovic [...] otrs.com>
Hello, I'm having performance issues with RGBA PNG files, when they are processed by the image_png() method. I'm supplying two screenshot files as a reproduction sample: one is plain RGB, the other one has an alpha channel as well. $ file screenshot-rgb.png screenshot-rgb.png: PNG image data, 2400 x 1800, 8-bit/color RGB, non-interlaced $ time perl -e 'use PDF::API2; PDF::API2->new()->image_png("screenshot-rgb.png")' real 0m0.174s user 0m0.140s sys 0m0.022s $ file screenshot-rgba.png screenshot-rgba.png: PNG image data, 2400 x 1800, 8-bit/color RGBA, non-interlaced $time perl -e 'use PDF::API2; PDF::API2->new()->image_png("screenshot-rgba.png")' real 0m40.619s user 0m40.412s sys 0m0.134s The difference in time needed to process both files is staggering. Is there any possibility to speed this up? The difference in file size is less than 30kB. Distribution: PDF-API2-2.033 Perl version: 5.18.2 OS: Mac OS 10.13.3 (Darwin Kernel Version 17.4.0) Thank you for your help! Regards, Dusan
Download screenshot-rgb.png
image/png 449.8k

Message body is not shown because sender requested not to inline it.

Download screenshot-rgba.png
image/png 479.8k

Message body is not shown because sender requested not to inline it.

I'm sure it's possible. The relevant code is in PDF/API2/Resource/XObject/Image/PNG.pm, which implements its own PNG parser. For anyone who'd like to take this on, here are a couple possible solutions: 1) Parsing could be delegated to another pure-Perl module where PNGs are the main focus (if one exists -- there are a bunch of modules in the Image::PNG namespace), or you can try profiling the code to see if there are any obvious optimizations that could be made. 2) The code could be modified to check to see if libpng (or a Perl module that relies on it) is present, and use that instead, if it exists. I don't want to add a non-Perl dependency requirement, but it's fine to use one if it's there. -- Steve On Wed Feb 07 05:42:16 2018, dusan.vuckovic@otrs.com wrote: Show quoted text
> Hello, > > I'm having performance issues with RGBA PNG files, when they are > processed by the image_png() method. > > I'm supplying two screenshot files as a reproduction sample: one is > plain RGB, the other one has an alpha channel as well. > > $ file screenshot-rgb.png > screenshot-rgb.png: PNG image data, 2400 x 1800, 8-bit/color RGB, > non-interlaced > > $ time perl -e 'use PDF::API2; > PDF::API2->new()->image_png("screenshot-rgb.png")' > > real 0m0.174s > user 0m0.140s > sys 0m0.022s > > > $ file screenshot-rgba.png > screenshot-rgba.png: PNG image data, 2400 x 1800, 8-bit/color RGBA, > non-interlaced > > $time perl -e 'use PDF::API2; > PDF::API2->new()->image_png("screenshot-rgba.png")' > > real 0m40.619s > user 0m40.412s > sys 0m0.134s > > > The difference in time needed to process both files is staggering. Is > there any possibility to speed this up? The difference in file size is > less than 30kB. > > Distribution: PDF-API2-2.033 > Perl version: 5.18.2 > OS: Mac OS 10.13.3 (Darwin Kernel Version 17.4.0) > > Thank you for your help! > > Regards, > Dusan
FYI, this is fixed in PDF::Builder (requires use of optional Image::PNG::Libpng library for improved speed, 32bps images, and interlacing). There is still quite a bit that could be done to improve the speed of either this library or its underlying libpng.a, and I have suggested this to the authors.