Post without Account — your post will be reviewed, and if appropriate, posted under Anonymous. You can also use this link to report any problems registering.

[RT 124349] Slow RGBA PNG processing performance

  • 2 Replies
  • 823 Views
*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 392
    • View Profile
[RT 124349] Slow RGBA PNG processing performance
« February 11, 2018, 08:54:51 AM »
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

<file screenshot-rgb.png too large to attach. get from GitHub (#85)>
<file screenshot-rgba.png too large to attach. get from GitHub (#85)>

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 392
    • View Profile
Re: [RT 124349] Slow RGBA PNG processing performance
« Reply #1: June 03, 2018, 12:11:21 PM »
Sat Jun 02 17:51:45 2018 steve [...] deefs.net - Correspondence added

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:

    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.

    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

Sat Jun 02 17:51:46 2018 The RT System itself - Status changed from 'new' to 'open'

Sat Jun 02 17:52:03 2018 steve [...] deefs.net - Severity Wishlist added

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 392
    • View Profile
Re: [RT 124349] Slow RGBA PNG processing performance
« Reply #2: June 03, 2018, 12:12:08 PM »
If users are experiencing such slowdowns on anything but a few edge cases, I would call it a bug rather than an enhancement ("wishlist") item. The current PNG code should certainly be examined to see if there are any reasonable fixes that could be made, and optionally make use of libpng or other such libraries if they offer a big improvement. Taking over 200 times as long when the "A" channel is used (transparency) is ridiculous, and hopefully there's a glaring error in there that could be fixed.