2

I'm using ImageSharp to convert some JPEG files from 4000x4000 (or so) images down to a set of different sized thumbnails (100x100, 250x250, 500x500 etc). The code below works pretty well, but wondering about any performance improvements - resizing and saving 3 thumbnails takes around a second per image, which isn't bad, but I'm wondering if there are any optimisations I can do to make it faster?

                var sizes = new[] { new Size (100), new Size (250), new Size (500) };
                using (var image = Image.Load<Rgb24>(sourceFileName))
                {
                    foreach (var size in sizes)
                    {
                        image.Mutate(x => x.Resize(size.Width, size.Height));
                        image.Save(dest);
                    }
                }

I know this lib will probably never get to the performance of GraphicsMagick (which is native C++ and highly optimised, and can do the same load + thumbnail transform in about 200ms) but I like the fact that it's cross-platform.

The lion's share of the time to do the work in ImageSharp is taken loading the image - is there a way to give it hints to load the JPEG in a faster way given that a lot of the resolution is going to be discarded with the thumbnail reduction anyway? Once it's loaded, the actual Resize and save-to-disk seems pretty quick.

I've also tried using a threadpool to transform (say) 6 images in parallel, which does give some improvement, but I just want to check if there's options or usage changes in ImageSharp itself that will make this significantly faster - checked the docs, but nothing obvious I can see so far.

stefan.seeland
  • 2,065
  • 2
  • 17
  • 29
Webreaper
  • 509
  • 4
  • 18
  • 1
    The total throughput is actually faster than GraphicsMagick. The slowest part of the code is, as you've correctly identified the jpeg decoder. Once we add a NET Core 3 target and new intriniscs I expect that performance to nearly double. – James South Oct 22 '19 at 02:59
  • Awesome, that's excellent. Thanks! My project is .Net Core 3.0 so will keep an eye out. Any expected ETA, or github issue I can watch? :) – Webreaper Oct 22 '19 at 07:27
  • 1
    I'm crossing my fingers here but I'm hoping 1st quarter next year. – James South Oct 23 '19 at 01:00
  • Just commenting to say this PR looks to be delivering exactly the solution discussed.... https://github.com/SixLabors/ImageSharp/pull/2076 – Webreaper Apr 02 '22 at 21:11

0 Answers0