unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
9k stars 733 forks source link

`SvgImageSource.ReadFromStreamAsync` could be optimized #14056

Closed Youssef1313 closed 6 months ago

Youssef1313 commented 1 year ago

What would you like to be added

Looking at the code:

#if __ANDROID__ || __SKIA__
    private async Task<ImageData> ReadFromStreamAsync(Stream stream, CancellationToken ct)
    {
        if (stream.CanSeek && stream.Position != 0)
        {
            stream.Position = 0;
        }

        var memoryStream = new MemoryStream();
        await stream.CopyToAsync(memoryStream, 81920, ct);
        var data = memoryStream.ToArray();
        return ImageData.FromBytes(data);
    }
#endif

Two optimizations come to mind:

Why is this needed

No response

For which platform

No response

Anything else we need to know?

No response

Youssef1313 commented 1 year ago

Trying to implement this fix, I found out that I need to change the signature of TryLoadSvgDataAsync which is public. So probably this would be postponed to Uno 6, unless someone sees a clever way of doing it without breaking the public API.

Youssef1313 commented 6 months ago

There is no enough evidence that it's really an issue in practice. Closing out