imazen / imageflow

High-performance image manipulation for web servers. Includes imageflow_server, imageflow_tool, and libimageflow
https://docs.imageflow.io/
GNU Affero General Public License v3.0
4.14k stars 140 forks source link

Png -> jpg conversion became >10x slower at v1.5.3-rc57 #576

Closed ogliznutsa closed 3 years ago

ogliznutsa commented 3 years ago

Starting from v1.5.3-rc57 png->jpg conversion is >10x slower.

Tests.zip

Imageflow.Net v0.7.21 + Imageflow.NativeRuntime.win-x86_64 v1.5.2-rc56:

Using ImageResizer to convert input.png -> imageresizer*.jpg in qualities 90..90 using maxwidth=500&format=jpg with parallel=True
Completed in 00:00:01.0542554
Using Imageflow to convert input.png -> imageflow_jpeg_turbo*.jpg in qualities 90..90 using maxwidth=500&format=jpg&jpeg.turbo=true with parallel=True
Completed in 00:00:00.3769430
Using Imageflow to convert input.png -> imageflow*.jpg in qualities 90..90 using maxwidth=500&format=jpg with parallel=True
Completed in 00:00:00.0383334

Imageflow.Net v0.7.21 + Imageflow.NativeRuntime.win-x86_64 v1.5.3-rc57:

Using ImageResizer to convert input.png -> imageresizer*.jpg in qualities 90..90 using maxwidth=500&format=jpg with parallel=True
Completed in 00:00:01.0349054
Using Imageflow to convert input.png -> imageflow_jpeg_turbo*.jpg in qualities 90..90 using maxwidth=500&format=jpg&jpeg.turbo=true with parallel=True
Completed in 00:00:04.2465038
Using Imageflow to convert input.png -> imageflow*.jpg in qualities 90..90 using maxwidth=500&format=jpg with parallel=True
Completed in 00:00:03.9138465

imageflow-dotnet-server gets stuck when doing such conversion - when deployed to Azure App Service (B1 app plan), it takes more than 40 seconds to convert 3 png files to jpg. We temporary downgraded imageflow-dotnet-server to v0.5.1 to use old native runtime under the hood.

ogliznutsa commented 3 years ago

@lilith could you please comment on the issue? Is it a bug or expected behavior?

lilith commented 3 years ago

I added proper background color rendering so that transparent pngs are not corrupted when converting to jpegs.

This is probably the cause. I assume this is only happening with 32 bit but not 24 bit PNGs?

On Fri, Feb 19, 2021, 5:00 AM Oleg Gliznutsa notifications@github.com wrote:

@lilith https://github.com/lilith could you please comment on the issue? Is it a bug or expected behavior?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow/issues/576#issuecomment-782031662, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LHZWEPT2DLVE3CL2VODS7ZHGNANCNFSM4XLGW5BQ .

ogliznutsa commented 3 years ago

@lilith Yes, 24 bit PNGs are not affected

lilith commented 3 years ago

This is the offending code: https://github.com/imazen/imageflow/blob/main/imageflow_core/src/graphics/blend.rs#L23-L43

There's no obvious way to fix the performance without sacrificing blending accuracy, so this may take a while to optimize/resolve.

lilith commented 3 years ago

Previously, transparent areas of PNGs were simply lifted to opacity with whatever random color data happened to be stored in those pixels, which caused lots of artifacts.

bwaldron commented 3 years ago

Thanks @lilith, sounds like the same. Would you recommend setting the background color (bgcolor) to avoid the perf cost for now?

lilith commented 3 years ago

It won't help - the default bgcolor is white.

On Mon, Mar 1, 2021, 7:53 PM Ben Waldron notifications@github.com wrote:

Thanks @lilith https://github.com/lilith, sounds like the same. Would you recommend setting the background color (bgcolor) to avoid the perf cost for now?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow/issues/576#issuecomment-788536447, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH3U2MJKXWEMDZKG6LTTBRHKBANCNFSM4XLGW5BQ .

lilith commented 3 years ago

I found a way to optimize it drastically. Try v1.5.6-rc60

bwaldron commented 3 years ago

Much appreciated, thanks!


From: Lilith River @.> Sent: Saturday, March 13, 2021 12:00:40 PM To: imazen/imageflow @.> Cc: Ben Waldron @.>; Comment @.> Subject: Re: [imazen/imageflow] Png -> jpg conversion became >10x slower at v1.5.3-rc57 (#576)

I found a way to optimize it drastically. Try v1.5.6-rc60

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/imazen/imageflow/issues/576#issuecomment-798776700, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAHPV5KPVGT5A2SDKRQI47DTDOY5RANCNFSM4XLGW5BQ.

ogliznutsa commented 3 years ago

Now works much faster, thanks @lilith !