ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: ctboeheim on April 22, 2022, 09:20:32 PM

Title: Time to call GetInfo degrades
Post by: ctboeheim on April 22, 2022, 09:20:32 PM
I'm writing a small program to calalog some images. I'm running into a problem where each time through the loop it slows down. I put a hi-res timer in the loop, and found that while the time to read each file remains constant at .01 second or less, the time to do the GetInfo on the in-memory image increases non-linearly over time. It starts out around .01 seconds; by image #250 it's over 1 second, by image #500 its 2.5 seconds, and by image 600 it's 3.5 seconds.  I don't see that I'm leaking any memory in the main loop, and I don't see any re-initialization calls for ExifTool to clear out stale data. Is there some reason for this slowdown?

Here's a minimal test program (perl 5.32, ExifTool 12.30):

#!/usr/local/bin/perl

use 5.010;

use strict;
use warnings;
no warnings "uninitialized";

use Image::ExifTool qw(:Public);
use File::Find;
use Time::HiRes qw(time);


my @tags = qw(
DateTimeOriginal CreateDate
ModifyDate       
ImageWidth  ExifImageHeight
ImageHeight ExifImageHeight
Make             
Model           
LensModel LensID LensInfo LensMake
Creator Artist By-line
DocumentID       
PreservedName   
);

my @files = @ARGV;

my $et = Image::ExifTool->new;

our $tm;
sub interval {
my $now = time;
my $int = $now - $tm;
$tm = $now;
return $int;
}

my $fileno = 0;
for my $file (@files) {
interval;
open(my $fh, "<:raw", $file) or die "Cannot open $file";
my ($dev, $inode, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($fh);
read($fh, my $image, $size);
my $readtime = interval;
my $info = $et->ImageInfo(\$image, \@tags);
my $infotime = interval;
close($fh);
$fileno++;

printf "File: %s Readfile: %s GetInfo: %s\n", $fileno, $readtime, $infotime;
}


Here's some timing output:

File: 1 Readfile: 0.0277459621429443 GetInfo: 0.0183801651000977
File: 200 Readfile: 0.0107479095458984 GetInfo: 0.350416898727417
File: 500 Readfile: 0.00974798202514648 GetInfo: 2.37377405166626
File: 600 Readfile: 0.00932002067565918 GetInfo: 3.5059039592742


Any insights would be appreciated.
Title: Re: Time to call GetInfo degrades
Post by: Phil Harvey on April 23, 2022, 05:17:04 PM
(sorry if you read my initial response -- I was looking at the wrong script)

You must re-initialize the @tags list at the start of each loop.  This will solve the problem.

Calling ImageInfo modifies this list.  (See the docs (https://exiftool.org/ExifTool.html#ImageInfo).)

An alternative is to do this:

   my $info = $et->ImageInfo(\$image, @tags);

(ie. pass all the tag names instead of the list reference)

- Phil
Title: Re: Time to call GetInfo degrades
Post by: ctboeheim on April 24, 2022, 03:32:55 PM
I see. That makes a huge difference in the results.
Thanks for identifying the problem!
-Chuck