C#

C#

Made by DeepSource

Use the method overload that accepts Span<T> instead of T[] when possible to reduce allocations CS-P1011

Performance
Major

Span<T> is a structure that is allocated on the stack rather than heap, thereby reducing the number of allocations during the program's lifetime which in return exerts less pressure on the GC. Since the method that you're trying to invoke has an overload that accepts Span<T>, it is therefore suggested that you use that overload and pass Span<T> rather than T[].

Bad Practice

// Implementation of `Foo()`
public void Foo(Span<T> s)
{
    //
}

// Calling `Foo()`
Foo(arr[1..3]);

Recommended

// Implementation of `Foo()`
public void Foo(Span<T> s)
{
    //
}

// Calling `Foo()`
Foo(arr.AsSpan()[1..3]);

Reference