Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image scaling and conversion is slow in iOS #2489

Open
4 tasks done
JPfahl opened this issue Jun 30, 2023 · 2 comments
Open
4 tasks done

Image scaling and conversion is slow in iOS #2489

JPfahl opened this issue Jun 30, 2023 · 2 comments
Labels
upstream-issue Issue depends on upstream dotnet fix.
Milestone

Comments

@JPfahl
Copy link

JPfahl commented Jun 30, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.0.1

Other ImageSharp packages and versions

None

Environment (Operating system, version and so on)

iOS 16.5.1

.NET Framework version

7

Description

I am using the Maui MediaPicker to take pictures on an iPhone. I am trying to use ImageSharp to fix the problems with MediaPicker, specifically that it returns the image as a png and does not honor phone orientation. I receive an ~18mb png from the media picker. Sizing it to a width of 1920 and saving as a jpg ~350kb with the right orientation takes ~17 seconds. Is there anyway to improve the speed. You product does exactly what I need but the performance makes it unusable in this case.

Steps to Reproduce

        Stream stream = await fileResult.OpenReadAsync();

        if (EnableImageSharp)
        {
            if (fileResult.ContentType == "png")
            {
                DateTime start = DateTime.Now;
                bool isPortrait = await MainThread.InvokeOnMainThreadAsync(() => 
                    DeviceDisplay.Current.MainDisplayInfo.Rotation ==
                    DisplayRotation.Rotation0 ||
                    DeviceDisplay.Current.MainDisplayInfo.Rotation ==
                    DisplayRotation.Rotation180);
                Sys.Log(isPortrait);
                SixLabors.ImageSharp.Image image =
                    await SixLabors.ImageSharp.Image.LoadAsync(new DecoderOptions()
                        {
                            TargetSize = new SixLabors.ImageSharp.Size(1920, 0)
                        },
                        stream);

                Sys.Log(stream.Length);
                stream.Dispose();
                Sys.Log(DateTime.Now - start);
                Sys.Log(image.Width);
                Sys.Log(image.Height);

                if (isPortrait)
                {
                    ushort portrait = 6;

                    image.Metadata.ExifProfile.SetValue(ExifTag.Orientation, portrait);
                    Sys.Log("Portrait");
                }

                stream = new MemoryStream();

                await image.SaveAsJpegAsync(stream);

                Sys.Log(DateTime.Now - start);
                Sys.Log(stream.Length);

                fileResult.FileName =
                    Path.ChangeExtension(fileResult.FileName, "jpeg");
            }
        }

Images

I can't provide an image because you don't accept anything over 10mb.

@JimBobSquarePants
Copy link
Member

Does anyone know what the intrinsics story is for Vector4 in iOS for .NET 7/8 + ?

We rely heavily on that type during resize.

@antonfirsov
Copy link
Member

antonfirsov commented Jul 5, 2023

I think 17 seconds is way too much for this to be about Vector4 or intrinsics. Mono AOT is essentially broken for open generics code we use heavily, falling back to very slow interpreted (?) execution, see dotnet/runtime#71210 (comment).

@JPfahl a comment/upvote on that issue may help to push them in order to have this fixed eventually.

@antonfirsov antonfirsov added upstream-issue Issue depends on upstream dotnet fix. and removed needs triage labels Jul 5, 2023
@antonfirsov antonfirsov added this to the Future milestone Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream-issue Issue depends on upstream dotnet fix.
Projects
None yet
Development

No branches or pull requests

3 participants