Socket.Unix: stackalloc IoVector/GCHandle for multi-buffer send/receives.#37583
Socket.Unix: stackalloc IoVector/GCHandle for multi-buffer send/receives.#37583stephentoub merged 4 commits intodotnet:masterfrom
Conversation
|
Tagging subscribers to this area: @dotnet/ncl |
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs
Show resolved
Hide resolved
|
@EgorBo @stephentoub @bbartels thanks for reviewing! |
| int maxBuffers = buffers.Count; | ||
| var handles = new GCHandle[maxBuffers]; | ||
| var iovecs = new Interop.Sys.IOVector[maxBuffers]; | ||
| Span<GCHandle> handles = allocOnStack ? stackalloc GCHandle[IovStackThreshold] : new GCHandle[maxBuffers]; |
There was a problem hiding this comment.
Since IovStackThreshold is so small, I wonder if it would be worth it to have a dedicated path for a small number of buffers and rather than using pinned GCHandles using fixed. The latter would necessitate writing out a fixed statement for each input, which is why it would need to be a small number, but it generally also has less overhead, in particular it's close to free when a GC doesn't occur, whereas there's always overhead to creating and free'ing GCHandles.
We can start with what you have and subsequently experiment with that if it's deemed a good idea, e.g. if we think two or three buffers for example is the most common case. Then again, this is all the synchronous code path, so maybe we needn't invest a ton in optimizing it further.
There was a problem hiding this comment.
Sounds like an interesting idea to try. The relative gain will be small due to the high cost of the syscall. Are there some cases where this optimization is performed already in corefx?
There was a problem hiding this comment.
Are there some cases where this optimization is performed already in corefx?
This one's pretty close:
There was a problem hiding this comment.
I could have sworn we did something like this for WSABuffers on Windows, but I can't find it now. Likely it was an experiment that never got checked in.
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs
Show resolved
Hide resolved
|
CI shows System.Net.Sockets.Tests Work Item failed, so probably something is wrong with this PR. I'll investigate. |
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs
Show resolved
Hide resolved
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs
Show resolved
Hide resolved
…#37583") (#40753) * Revert " Use clonefile for CopyFile, if available (dotnet/corefx#37583)" This reverts commit 02ba75a. * Add unit test * Disable tests failing in browser-wasm
cc @stephentoub @roji