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

JpegDecoder very slow in Blazor client side app #2069

Closed
4 tasks done
Neralem opened this issue Mar 22, 2022 · 2 comments
Closed
4 tasks done

JpegDecoder very slow in Blazor client side app #2069

Neralem opened this issue Mar 22, 2022 · 2 comments
Labels
invalid upstream-issue Issue depends on upstream dependency fix.

Comments

@Neralem
Copy link

Neralem commented Mar 22, 2022

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

2.1.0

Other ImageSharp packages and versions

None

Environment (Operating system, version and so on)

Windows 11

.NET Framework version

.Net 6

Description

I'm currently writing a Blazor Client Side application where i need some raw pixel data of pretty large jpeg images. Please take a look at the following code:

using (MemoryStream ms = new MemoryStream(bytes))
{
    JpegDecoder decoder = new JpegDecoder();
    var image = decoder.Decode<Rgb24>(Configuration.Default, ms, CancellationToken.None)}

Assume that bytes is a byte array filled with the data of a 5000x5000 pixel jpeg file, this code needs about 5 Minutes to complete. I've tested this with several browsers in release and debug mode.

If i run the same code on the same machine in a WPF desktop app, it is pretty fast (3 sec or something like that).

If i evaluate System.Numerics.Vector.IsHardwareAccelerated, which I saw in similar issues, I get false on my Blazor App but true on my WPF Desktop app. I assume this is the problem but I am still shocked how much difference hardware acceleration brings in case of decoding a jpeg.

What can I do to fix this?

Steps to Reproduce

Create a new Blazor Clientside App and paste the code above in any code block to run it.

@JimBobSquarePants
Copy link
Member

It's not an issue with ImageSharp.

Blazor WASM lacks any SIMD support. See dotnet/runtime#51709
It's likely also running in Interpreted mode due to the default configuration which kills performance. https://blog.stevensanderson.com/2018/02/06/blazor-intro/

You can try enabling AOT compilation for better performance but be aware there are limitations in the compiler which can sometimes cause it to slip back to interpreted mode.
https://blog.elmah.io/ahead-of-time-compilation-for-blazor-wasm/

Other than that. Use Server side Blazor. Client side IMO isn't fit for purpose.

BTW. Never use a decoder directly unless you are 100% certain of the format of the encoded image (file extensions can lie).

@JimBobSquarePants JimBobSquarePants added invalid upstream-issue Issue depends on upstream dependency fix. and removed needs triage labels Mar 22, 2022
@Neralem
Copy link
Author

Neralem commented Mar 22, 2022

@JimBobSquarePants Thanks for your input and suggestions! I've tried the AOT-Compile Solution but sadly it's still as slow as it was. I really hope this will improve some day :(

Yeah I am sure about the format :) The API the images are pulled from is in my hand - so is the client that creates those images. I think I'll switch to png which is a lot larger but way faster to decode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid upstream-issue Issue depends on upstream dependency fix.
Projects
None yet
Development

No branches or pull requests

2 participants