Skip to content

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

Merged
mattleibow merged 9 commits into
dotnet:mainfrom
MartyIX:feature/2024-07-25-PlatformImage.FromStream-seekable-optimized
Aug 1, 2024
Merged

[Windows] Handle non-seekable streams in PlatformImage.FromStream (take 2)#23824
mattleibow merged 9 commits into
dotnet:mainfrom
MartyIX:feature/2024-07-25-PlatformImage.FromStream-seekable-optimized

Conversation

@MartyIX

@MartyIX MartyIX commented Jul 25, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Comment thread src/Graphics/src/Graphics/Platforms/Windows/PlatformImage.cs Outdated
Comment thread src/Graphics/src/Graphics/Platforms/Windows/PlatformImage.cs Outdated
@jonathanpeppers

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@jonathanpeppers jonathanpeppers left a comment

Copy link
Copy Markdown
Member

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.

Comment thread eng/NuGetVersions.targets
Comment thread src/Graphics/src/Graphics.Win2D/Graphics.Win2D.csproj Outdated
Comment thread src/Graphics/src/Graphics/Platforms/Windows/PlatformImage.cs
@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
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

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

@mattleibow mattleibow left a comment

Copy link
Copy Markdown
Member

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

Comment thread src/Graphics/src/Graphics/Platforms/Windows/PlatformImage.cs Outdated
Comment thread src/Graphics/src/Graphics/Platforms/Windows/PlatformImage.cs Outdated
Comment thread eng/NuGetVersions.targets
@MartyIX

MartyIX commented Jul 29, 2024

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@mattleibow mattleibow left a comment

Copy link
Copy Markdown
Member

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