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

[Windows] Handle non-seekable streams in PlatformImage.FromStream (take 2) #23824

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
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 jonathanpeppers and Foda and removed request for Eilon and tj-devel709 July 25, 2024 09:00
@jonathanpeppers
Copy link
Member

/azp run

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

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

eng/NuGetVersions.targets Show resolved Hide resolved
@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

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
97 checks passed
@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