jpdillingham / Soulseek.NET

A .NET Standard client library for the Soulseek network.
GNU General Public License v3.0
175 stars 24 forks source link

Refactor Connection ReadAsync()/WriteAsync() to use Memory<T> #626

Closed jpdillingham closed 2 years ago

jpdillingham commented 2 years ago

I'm doing some performance profiling on transfer speeds and was curious how the internal Stream.CopyTo() was written. The method I'm using currently closely matches the implementation for .NET Framework, but the .NET Core implementation is different:

https://github.com/dotnet/corert/blob/master/src/System.Private.CoreLib/shared/System/IO/Stream.cs

This isn't the newest implementation, either, as the .NET source has moved and I'm pretty sure newer stuff is using pipes. I have an older branch here that experimented a bit with these.

Because this code dictates how transfers perform in terms of both speed and system resource usage, it should represent the "latest and greatest". Unfortunately, backward compatibility makes this a complex task. Additional preprocessor directives will need to be added to support NETSTANDARD2_0.

jpdillingham commented 2 years ago

This appears to be the latest source: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs#L87-L118