simplify PreAllocatedOverlapped lifetime management#10302
simplify PreAllocatedOverlapped lifetime management#10302geoffkizer wants to merge 1 commit intodotnet:masterfrom
Conversation
|
This logic you are removing seems to be protecting against finalization races. I do not understand this well enough to tell whether it is ok remove it. |
| /// Frees the resources associated with this <see cref="PreAllocatedOverlapped"/> instance. | ||
| /// </summary> | ||
| public unsafe void Dispose() | ||
| unsafe void Dispose(bool disposing) |
| /// </summary> | ||
| /// <seealso cref="ThreadPoolBoundHandle.AllocateNativeOverlapped(PreAllocatedOverlapped)"/> | ||
| public sealed class PreAllocatedOverlapped : IDisposable, IDeferredDisposable | ||
| public sealed class PreAllocatedOverlapped : IDisposable |
There was a problem hiding this comment.
You can delete IDeferredDisposable and DeferredDisposableLifetime as well.
|
@geoffkizer, from a quick read, it appears that logic is protecting against Dispose'ing a PreAllocatedOverlapped while a NativeOverlapped created from it is still in use (similar to SafeHandle deferring its disposal until all outstanding ref counts from P/Invokes and other Dangerous usage have completed). We don't care about that? |
|
Yeah, I pushed this too quickly. We don't care about deferred dispose in Sockets because we already manage the deferred dispose ourselves. But since this is public, other uses may care. We don't need full AddRef/Release, since AddRef is not exposed and is never called internally except from AllocateNativeOverlapped. But to handle deferred dispose, we do need to distinguish between in-use and not in use. I'll take another look at this. |
|
BTW, the more general issue here is that the way the PreAllocatedOverlapped-related APIs work is not great from a perf point of view -- there's a nontrivial amount of overhead in AllocateNativeOverlapped and FreeNativeOverlapped. In the Socket code, we are explicitly managing the lifetime and state of the overlapped object ourselves. All we really want is a way to say "please reset the state on this overlapped so we can use it again". This should be cheap in theory. |
|
Closing for now. I will revisit later. |
PreAllocatedOverlapped has some lifetime management state/logic that is not used in practice. Remove this.
On my socket microbenchmark, this seems to give a small win (1-1.5%), though it may be noise.
@jkotas @stephentoub