dotnet / dotnet/SqlClient

SqlStream and SqlCachedStream should consider overriding Span Read/Write methods

Open
#1,628 1 comment 3 reactions 0 assignees View on GitHub
Performance :chart_with_upwards_trend:
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.