SqlStream and SqlCachedStream should consider overriding Span Read/Write methods
- Dominant language
- C#
- Stars
- 989
- Forks
- 340
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 72
Description
Since .NET Core 2.1, `System.IO.Stream` has had Read and Write overloads that accept a Span to read to / write from. However, the base Stream implementation isn't optimized. To get the best performance when a caller is using the Span-based APIs, derived implementations of Stream are expected to override the Span-based APIs and perform the operation on the Spans. See the `System.IO.Stream` section of https://github.com/dotnet/runtime/issues/22387 for more information.
We should consider overriding the Span Read/Write methods on these classes:
https://github.com/dotnet/SqlClient/blob/f2635caf75f69df1256edf3dd18b954672651b3e/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlStream.cs#L16
https://github.com/dotnet/SqlClient/blob/f2635caf75f69df1256edf3dd18b954672651b3e/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlStream.cs#L270
That way callers using the Span-based APIs get better performance - an ArrayPool buffer doesn't need to be rented, and the data copied twice.
See more conversation here: https://github.com/dotnet/runtime/pull/69879#discussion_r884002561
Contributor guide
Assessment
This issue has not been assessed yet.