This project has moved. For the latest updates, please go here.

Big difference in Speed between version 6 and 7

Sep 22, 2016 at 9:21 AM
Edited Sep 22, 2016 at 10:18 AM
I have been using Magick.net verion 6 for years.
the distort command in the code below is taken about 38 ms. on the same environment with version 7 it takes 200 to 240 ms. Did I do something wrong? do I need to change something in new version?
I use q8-Any-cpu

for test you can create a console application and use this code and switch between magick.net 6 and 7. if you use any image you can see the difference in the speed.
class Program
{
    static void Main(string[] args)
    {

        MagickReadSettings readSettings = new MagickReadSettings();
        readSettings.Format = MagickFormat.Bmp;
        readSettings.Width = 590;
        readSettings.Height = 590; 

        var image = new MagickImage(@"d:\temp\mypic.bmp", readSettings);


        double[] defaultcoordinate =
        {
            0,
            0,
            43.78,
            195.26,
            590,
            0,
            405.97,
            203.69,
            590,
            590,
            405.97,
            620.90,
            0,
            590,
            113.78,
            488.85
        }; 

        var coordinates = defaultcoordinate;

        var distortImageMethod = DistortMethod.Perspective;
        image.VirtualPixelMethod = VirtualPixelMethod.White;

        image.Distort(distortImageMethod, coordinates);

        image.Dispose();
    }

I have found a clue: even in the first versions of 7 - from version 7.0.0.1 to 7.0.0.22 - the process time of the distort with that image is around 40 ms to 70 ms and suddenly from version 7.0.0.104 it jumps to 194 - 200 ms.
Coordinator
Sep 22, 2016 at 12:49 PM
Is distort only slower than it used to be? Or is the whole process slower? Maybe the startup is now slower because of the native library that was added in 101? Can you do the distort in a loop and test what happens?
Sep 22, 2016 at 2:08 PM
I checked it with loop and still all the distort command are over 200 ms. I checked the composite command and it is working as usual

this command : iimage.Composite(colormap, Gravity.Center, CompositeOperator.Displace, string.Format("{0}x{1}", 70, 60));

is executed less than 89 ms which is fast and good but the distort command has unusual performance.
so this is just the distort command which has poor performance.

Thanks for your reply.
Coordinator
Sep 22, 2016 at 5:02 PM
Edited Sep 22, 2016 at 5:10 PM
Which exact version did you see the performance issue. There are a couple version between .22 and .104. This will make it easier to track down why this is happening. It might be caused because I disabled OpenMP so you no longer need to install the C++ redistributable. Can you try it in a parallel for loop?
Sep 23, 2016 at 10:28 AM
this is happening exactly between these two version:

Magick.NET 7.0.0.0022
Nov 23, 2015, Alpha

Magick.NET 7.0.0.0101
Feb 4, 2016, Alpha

I tested it with parrallel loop, and I can confirm that it works very good. for 10 distort commands the whole time is 500 ms (for each distort is 50 ms four times faster)

But how can I run it fast with single threat and not parallel ?

I also uninstall the c++ redistributable but no changes in performance.
Coordinator
Sep 23, 2016 at 2:25 PM
Magick.NET 7.0.0.0022 and lower use OpenMP that will run some operations a bit faster in a single thread. I had to drop support for that to make it possible to use Magick.NET without installing the C++ redistributable. This will mean that you won't get the performance you used to have. And if you handle multiple images at the same time you should get the same performance. I will try and see if I can figure out why the change is this big but that might take me a while.