Subject: | Image::Info::SVG slow and inaccurate |
Image::Info::SVG::process_file is unnecessarily slow for big SVG
files. For instance, image_info takes more than four minutes to
get the result for a 10MB SVG file. The problem is that
process_file() uses XML::Simple, which uses the relatively slow
SAX parser (a better solution would be XML::LibXML::Reader), and
what's worse, it creates a huge perl data structure, from which
only a small fraction is used for image_info.
An alternative implementation with XML::LibXML::Reader takes less
than one second for the same file. I can provide this solution.
But this would add XML::LibXML as a new dependency, which is
probably not as easy to satisfy as XML::Simple. AFAIK it is
possible to use XML::Simple with pure-perl modules, while
XML::LibXML requires the presence of a recent libxml2 and a
compiler. So I suggest to keep the old slow solution (maybe named
Image::Info::SVG::_XMLSimple), create the new module as
Image::Info::SVG::_XMLLibXMLReader, and Image::Info::SVG would
just be a switch between both.
An additional benefit of the XML::LibXML-based solution is that
extracting comments actually works. In the attached sample output
you can see that the 'Comment' is obviously wrong with the
current Image::Info::SVG.
If you agree on everything, then I can provide a proper patch, or
even complete new distribution.
Regards,
Slaven
Subject: | image_info_svg_timing.txt |
$ ls -al /tmp/bbbikedraw.svg
-rw-r--r-- 1 eserte wheel 10069222 22 Nov 13:27 /tmp/bbbikedraw.svg
$ time perl -MData::Dumper -MImage::Info=image_info -e 'warn Dumper(image_info(shift))' /tmp/bbbikedraw.svg
$VAR1 = {
'width' => '640',
'file_media_type' => 'image/svg+xml',
'SVG_StandAlone' => 'yes',
'file_ext' => 'svg',
'Comment' => ' <line id="36377-620-8" style="fill: rgb(0,0,128); fill-opacity: 1.0; stroke: rgb(0,0,128); stroke-opacity: 1.0; stroke-width: 1; stroke-linecap: square" x1="620" x2="623" y1="8" y2="8" />Generated using the Perl SVG Module V2.38
by Ronan Oger
Info: http://www.roitsystems.com/',
'color_type' => 'sRGB',
'height' => '480',
'SVG_Version' => 'unknown'
};
perl -MData::Dumper -MImage::Info=image_info -e /tmp/bbbikedraw.svg 270,79s user 0,22s system 96% cpu 4:42,23 total
$ time /usr/perl5.8.9@RC1/bin/perl ~/devel/Image_Info_SVG_LibXML.pm /tmp/bbbikedraw.svg
Line 107, File: /home/e/eserte/devel/Image_Info_SVG_LibXML.pm
$VAR1 = {
'file_media_type' => 'image/svg+xml',
'width' => '640',
'file_ext' => 'svg',
'SVG_StandAlone' => 'yes',
'Comment' => '
Generated using the Perl SVG Module V2.38
by Ronan Oger
Info: http://www.roitsystems.com/
',
'color_type' => 'sRGB',
'height' => '480',
'SVG_Version' => 'unknown'
};
/usr/perl5.8.9@RC1/bin/perl ~/devel/Image_Info_SVG_LibXML.pm 0,60s user 0,01s system 96% cpu 0,638 total