Remove per-async operation allocation from Sockets on Unix by stephentoub · Pull Request #32919 · dotnet/corefx (original) (raw)

On Unix, we have a dedicated thread monitoring epoll/kqueues; when events are processed, we then queue those to the thread pool for executing callbacks, as otherwise that sole dedicated thread could get blocked and prevent all other socket operations from being handled. Today, that queueing is done with ThreadPool.UnsafeQueueUserWorkItem(delegate,state), which involves a small allocation internal to ThreadPool for each operation. Now that we're adding IThreadPoolWorkItem in .NET Core 3.0, and since we already have an object to represent each of these operations, we can just use ThreadPool.UnsafeQueueUserWorkItem(workItem, bool) to queue the operations without additional allocations.

Depends on #32859. I've not yet measured to see what throughput impact this has, if any; that'll be easier to do once the dependencies are in (that PR is blocked on waiting for coreclr changes that propagated to corert to then propagate back to corefx).
cc: @geoffkizer, @davidfowl, @vancem, @davidsh