Skip to content

Switch to Span<T> or ReadOnlySpan<T> #2616

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

Open
4 of 35 tasks
Tracked by #2615
mattleibow opened this issue Sep 18, 2023 · 2 comments
Open
4 of 35 tasks
Tracked by #2615

Switch to Span<T> or ReadOnlySpan<T> #2616

mattleibow opened this issue Sep 18, 2023 · 2 comments
Labels
area/SkiaSharp Issues that relate to the C# binding of SkiaSharp. status/up-for-grabs tenet/performance Performance related issues type/enhancement

Comments

@mattleibow
Copy link
Contributor

mattleibow commented Sep 18, 2023

Description

Part of #2615

The SkiaSharp codebase is quite old and existed before the introduction of spans. (See more https://learn.microsoft.com/en-us/dotnet/standard/memory-and-spans/memory-t-usage-guidelines)

Current files in the core binding using arrays:

  • Definitions.cs
  • GRGlInterface.cs
  • GRVkExtensions.cs
  • SKBitmap.cs
  • SKCanvas.cs
  • SKCodec.cs
  • SKColorFilter.cs
  • SKColorSpace.cs
  • SKColorSpaceStructs.cs
  • SKData.cs
  • SKFont.cs
  • SKFontManager.cs
  • SKFrontBufferedManagedStream.cs
  • SKFrontBufferedStream.cs
  • SKImage.cs
  • SKManagedStream.cs
  • SKManagedWStream.cs
  • SKMaskFilter.cs
  • SKMatrix.cs
  • SKMatrix44.cs
  • SKObject.cs
  • SKPMColor.cs
  • SKPaint.cs
  • SKPath.cs
  • SKPathEffect.cs
  • SKRoundRect.cs
    • Start using spans instead of arrays #2617
    • public SKPoint[] Radii { get; } still exists as it is a convenience and this is accessible using non-arrays by querying each corner individually (which is what this property does)
  • SKRuntimeEffect.cs
  • SKShader.cs
  • SKStream.cs
  • SKString.cs
  • SKTextBlob.cs
  • SKTypeface.cs
  • SKVertices.cs
  • SkiaApi.generated.cs
  • Util.cs

NOTE: not all usages are bad. There are cases where returning an array is acceptable because we have span alternatives, or the data is best contained in an array.

@xoofx
Copy link

xoofx commented Feb 25, 2025

Hey Matthew, I'm currently prototyping with Avalonia, and there are plenty of places in the code where Avalonia allocates a lot because there are missing Span APIs in SkiaSharp.

Would it be ok If I was making a single PR to bring Span for all existing APIs? I haven't checked how much work it could be but I see that there are some pending PR that did some parts, so wondering why they are not merged? Or I could do all of them in one go.

Let me know. ☺️

@xoofx
Copy link

xoofx commented Feb 26, 2025

Actually #2669 is maybe covering what is left so I will followup with this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/SkiaSharp Issues that relate to the C# binding of SkiaSharp. status/up-for-grabs tenet/performance Performance related issues type/enhancement
Projects
Status: Ready For Work
Development

No branches or pull requests

2 participants