Hi,
XPM loading used to be really slow. Probably it was designed for small
icons, but people (like me) are using (or using software which uses)
big files (see http://linuxgazette.net/102/washko.html if you wanna
know why).
The old code had a major performance bug: it used strlcpy (by way of
CopyMagickString) to copy the first characters of a string, i.e.:
const char* very_long = "ABCDEFGH..........";
char* short;
strlcpy(short,very_long,4); /* give me "ABC"
this works, but strlcpy returns strlen(very_long), so it must scan the
whole string (took me a long time to figure this one out, this is a
real performance gotcha to look out for). Just correcting this, gets
the code to be about 2 orders of magnitude times faster.
The rest of the optimizations makes it twice as fast. The code used to
copy the file in memory a couple of times, it doesn't do that anymore,
its all in-place. Furthermore, it sorts the table and uses bsearch
instead of a linear lookup (the older code did do a cache-last-result,
but this is visibly better).
Here are the performance numbers on converting xpm -> jpg on a newish
linux-based pentium iv (four different large files):
Version 6.3.0:
39.77s user 0.12s system 99% cpu 39.954 total
67.62s user 0.15s system 99% cpu 1:07.79 total
67.06s user 0.11s system 99% cpu 1:07.24 total
74.81s user 0.13s system 99% cpu 1:15.04 total
With patch:
0.18s user 0.03s system 76% cpu 0.276 total
0.21s user 0.03s system 68% cpu 0.352 total
0.22s user 0.03s system 78% cpu 0.320 total
0.25s user 0.04s system 80% cpu 0.359 total
(this is using "time" which is good enough when the difference are this
huge)
It used to take over one minute on a good machine! (over 4 minutes on
my apple laptop, which is by now oldish. I don't think it can be made
any better now.
I hope this gets into the next version of image magic.
luis
_______________________________________________
Magick-developers mailing list
Magick-developers@imagemagick.org
http://studio.imagemagick.org/mailman/listinfo/magick-developers