Description
There is around an ~80x performance regression in System.Numerics.Tensors TensorSpan<T>.FlattenTo (and ReadOnlyTensorSpan<T>.FlattenTo).
Prior to 10.0.0-preview.4.25258.110 the implementation copied to the destination in blocks but now copies per-element.
Reproduction + benchmark solution here
Run FlattenTo.Before and FlattenTo.After console apps to benchmark against each package version.
Regression?
This performance issue was not present in the stable 9.0.10 release however the package was marked Experimental before .NET 10.
10.0.0-preview.3.25171.5 is the last version before the rewrite #114927 that introduced TensorOperation.
Data
| Method |
Mean |
Error |
StdDev |
Allocated |
| FlattenToBefore |
25.16 μs |
0.136 μs |
0.120 μs |
48 B |
| FlattenToAfter |
1.936 ms |
0.0013 ms |
0.0011 ms |
- |
Before-Benchmarks.log
After-Benchmarks.log
Analysis
release/9.0
|
public void FlattenTo(scoped Span<T> destination) |
release/10.0-rc2
|
public void FlattenTo(scoped Span<T> destination) |
|
public static void Invoke<TOperation, TArg, TResult>(in ReadOnlyTensorSpan<TArg> x, in Span<TResult> destination) |
cc: @tannergooding
Description
There is around an ~80x performance regression in
System.Numerics.TensorsTensorSpan<T>.FlattenTo(andReadOnlyTensorSpan<T>.FlattenTo).Prior to
10.0.0-preview.4.25258.110the implementation copied to the destination in blocks but now copies per-element.Reproduction + benchmark solution here
Run
FlattenTo.BeforeandFlattenTo.Afterconsole apps to benchmark against each package version.Regression?
This performance issue was not present in the stable
9.0.10release however the package was markedExperimentalbefore .NET 10.10.0.0-preview.3.25171.5is the last version before the rewrite #114927 that introducedTensorOperation.Data
Before-Benchmarks.log
After-Benchmarks.log
Analysis
release/9.0
runtime/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan.cs
Line 768 in 9c2fb4b
release/10.0-rc2
runtime/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs
Line 352 in 9a6bee3
runtime/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorOperation.cs
Line 156 in 9a6bee3
cc: @tannergooding