ImagesToBlob is slow

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
vitaminwater
Posts: 4
Joined: 2015-04-22T13:55:27-07:00
Authentication code: 6789

ImagesToBlob is slow

Post by vitaminwater »

Hi,

I'm building a small web server that crops/resizes gif(note: I'm using JMagick and Java). It works great but I'm having 2 issues.

1. I use coalesce and optimizeLayers method for resizing gif. The issue is converting resized gif(ImagesToBlob) to byte array is extremely slow(takes 3-4 sec for 2MB gif with 60 frames), I believe it's related to 'coalesce' operation. I even noticed it in command line.

Code: Select all

time convert cat.gif -coalesce -layers optimize cat-1.gif
real	0m2.880s
user	0m2.725s
sys	0m0.109s
Is it normal behavior? Can it be optimized?

2. The above issue is much worser in multi-thread environment.
Here is time of resizing a single gif:
Single thread: 1357ms
Multi thread: 96267ms(4 threads)

I have OpenMP disabled and set MAGICK_TMPDIR to a big disk.

My system info:
2.7 GHz Intel Core i7
16 GB 1600 MHz DDR3

Appreciate for any comments or help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImagesToBlob is slow

Post by fmw42 »

Creating gif files can be slow due to the color quantization. You can try using -tree-depth to make it faster, but less accurate colors. See http://www.imagemagick.org/script/quantize.php and http://www.imagemagick.org/script/comma ... #treedepth.

Coalesce needs to fill out partial frames and that also can be slow. More cores/threads might help, but on some systems it can be slower than limiting the thread to 1.
vitaminwater
Posts: 4
Joined: 2015-04-22T13:55:27-07:00
Authentication code: 6789

Re: ImagesToBlob is slow

Post by vitaminwater »

Thanks for the suggestion.

Is it slow because of reading/writing to disk(since memory isn't big enough)? How much memory does it need not to use disk? Also, what are you referring to as 'some systems'?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImagesToBlob is slow

Post by fmw42 »

What are the physical dimensions of the gif (WxHxframes) and is there transparency. IM will need at least twice the size of
W x H x frames x 32bits/pixel until it quantizes and compresses the output. Certain Linux systems, I am told, may not work well with some IM functions with multiple cores. They run slower. You did not say what platform you are using. I am guessing a Mac. I have not seen that problem before on a Mac.
vitaminwater
Posts: 4
Joined: 2015-04-22T13:55:27-07:00
Authentication code: 6789

Re: ImagesToBlob is slow

Post by vitaminwater »

400x225x60 frames. Uploaded the original image here http://uploadpie.com/eEYDb.

I'm using a Mac. Here's what IM has on my machine.

Code: Select all

 $ convert -list resource
Resource limits:
  Width: 214.7MP
  Height: 214.7MP
  Area: 4.295GP
  Memory: 2GiB
  Map: 4GiB
  Disk: unlimited
  File: 192
  Thread: 1
  Throttle: 0
  Time: unlimited
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImagesToBlob is slow

Post by fmw42 »

400x225x60*32*2=345600000 bytes = 345.6 Mbytes (my estimate of RAM needed)
Post Reply