Skip to content

Conversation

@MartyIX
Copy link
Contributor

@MartyIX MartyIX commented Jul 25, 2024

Alternative to #23626. This PR uses the RecyclableMemoryStreamManager to decrease allocations.

Description of Change

AsRandomAccessStream throws NotSupportedException when the stream is not seekable. This PR is a simple workaround for it.

The second commit adds an optimization. The idea is to remove AsyncPump (introduced in dotnet/Microsoft.Maui.Graphics@4597923 and merged to MAUI in #8739) which does not seem to be necessary at all. I have tested the change with parallel loading of images and it did not break for me. But then again I don't really know why AsyncPump was introduced in the first place. This commit is an alternative to #23624 approach and the improvement should be the same as in that PR: #23624 (comment) (9 seconds -> 1.3 seconds for a batch of images containing ~100 images).

Test

Tested with provided sample code that reads images in parallel to make sure it works: https://gist.github.com/MartyIX/2513b1853ad8537a4d31b62c251115ad

animation

Issues Fixed

Fixes #18954

@MartyIX MartyIX requested a review from a team as a code owner July 25, 2024 08:50
@MartyIX MartyIX requested review from Eilon and tj-devel709 July 25, 2024 08:50
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jul 25, 2024
@dotnet-policy-service
Copy link
Contributor

Hey there @MartyIX! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@MartyIX MartyIX requested review from Foda and jonathanpeppers and removed request for Eilon and tj-devel709 July 25, 2024 09:00
@jonathanpeppers
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me 👍, I triggered CI.

@MartyIX MartyIX force-pushed the feature/2024-07-25-PlatformImage.FromStream-seekable-optimized branch from b41d163 to 45b9ff3 Compare July 26, 2024 08:57
@rmarinho
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@MartyIX MartyIX requested a review from jonathanpeppers July 27, 2024 09:05
Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good!

Is it possible to create a test for this? You can fake a readonly stream with something like this: https://github.com/mono/SkiaSharp/blob/main/tests/Tests/Utils/NonSeekableReadOnlyStream.cs

@MartyIX
Copy link
Contributor Author

MartyIX commented Jul 29, 2024

This is looking good!

Is it possible to create a test for this? You can fake a readonly stream with something like this: https://github.com/mono/SkiaSharp/blob/main/tests/Tests/Utils/NonSeekableReadOnlyStream.cs

Yes, I will try to come with one.

@MartyIX MartyIX force-pushed the feature/2024-07-25-PlatformImage.FromStream-seekable-optimized branch from 45b9ff3 to d1e5a3e Compare July 29, 2024 21:35
@rmarinho
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!

@mattleibow mattleibow merged commit 4856f37 into dotnet:main Aug 1, 2024
@MartyIX MartyIX deleted the feature/2024-07-25-PlatformImage.FromStream-seekable-optimized branch August 1, 2024 05:15
@github-actions github-actions bot locked and limited conversation to collaborators Sep 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution fixed-in-8.0.80

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] PlatformImage.FromStream crash

6 participants