Menu

#75 Optimize HEIC identify performance by deferring libheif initialization

closed-fixed
None
5
2025-11-09
2025-11-07
No

Hi Bob,
This is not technically a request as I would be willing to put up the change. I just wanted to get your view on it before I dive in. I have seen identify commands like getting the image format take much longer for HEIC images than for JPG. Where a JPG might take 20ms to get the image format, an HEIC image can take a more than a second.

I suspect what is going on is that the libheif library is being initialized. If that is the case it would seem that we could avoid that for some identify commands. Again, I'm speculating on the cause. Let me know what you think and if you think this might be the root cause and if I were to put up a patch whether this type of change is something you would approve. Thanks, I very much appreciate all your hard work.

Discussion

  • Bob Friesenhahn

    Bob Friesenhahn - 2025-11-07

    Thanks for bringing the strange pause to my attention. The problem is not with library initialization. The problem is that the default identify 'ping' mode is not being respected. I am investigating.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2025-11-07

    The problem is that 'ignore_transformations' is false by default and so it does some file decoding to find the real image dimensions and some other info. Adding this to the identify request makes it go fast:

    -define heif:ignore-transformations=true

    If the default condition is changed, then it will be fast by default, but then the user must specify

    -define heif:ignore-transformations=false

    In order to assure accurate dimensions (e.g. in case the image is rotated).

    Bob

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2025-11-07
    • status: open --> closed-fixed
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2025-11-07

    I have submitted this change:

    (ReadHEIFImage): Invert the sense of ignore_transformations.
    Default 'ignore_transformations' to true since otherwise
    'identify' can be very slow due to doing much of the work involved
    with reading the file.  The user should pass '-define
    heif:ignore-transformations=false' if a fully accurate report of
    image dimensions (and some other information) is required.  This
    is to address the concern raised in issue #75 "Optimize HEIC
    identify performance by deferring libheif initialization".
    

    in this Mercurial changeset:

    17843:e94eccae0651
    tag: tip
    user: Bob Friesenhahn bfriesen@GraphicsMagick.org
    date: Fri Nov 07 13:15:47 2025 -0600
    files: ChangeLog coders/heif.c doc/options.imdoc utilities/gm.1 www/ChangeLog.html www/GraphicsMagick.html www/gm.html
    description:
    coders/heif.c (ReadHEIFImage): Invert the sense of ignore_transformations. Default 'ignore_transformations' to true.

    Bob

     
  • Kevin Clauson

    Kevin Clauson - 2025-11-09

    Wow! Thanks Bob!
    I got hit by the flu, so was down the past few days with a high fever. I was just feeling better so I thought I would check if you had responded and here I find not only have you responded, but you have given me the fix. Feeling even better now, thanks again!

     

Log in to post a comment.

MongoDB Logo MongoDB