Socket.Unix: stackalloc IoVector/GCHandle for multi-buffer send/receives. by tmds · Pull Request #37583 · dotnet/runtime (original) (raw)

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.