-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change new QueueUserWorkItem method to use TState
#25193
Comments
So very much for this!
readonly static WaitCallback lamda = state => ((Action)state)(); Which also means for |
YESSSS 😄 |
But the implementation is still going to allocate the workitem on the heap, right? Isn't it just shifting where the boxing happens? |
I'm not following. The ThreadPool allocates an IThreadPoolWorkItem implementation to store into the queue. That IThreadPoolWorkItem contains the delegate, the object state, and additional state like ExecutionContext. That's true whether or not the object state is a value type that was boxed. The boxing is yet another allocation on top of that work item object. If you mean the value type is still going to end up on the heap, then yes. But it's going to end up there as part of the one object rather than having a separate one allocated for it. |
Right, that's what I meant. So it saves ~3 pointers worth of allocation per work item. This saving does not depend on the state size. |
That's not what I intended to suggest, and in general I'd expect the number to be small, e.g. 2, for example another state-accepting delegate with a different type and the associated state to go with it. |
@jkotas may not like it but what if |
It'll eventually get boxed when the in ExecutionContext.Run happens. |
I expect that the implementation of the proposed API is going to use type like this internally. Potentially two types like this if it does the optimization for default execution context like the current QueueUserWorkItem. |
Yup. |
T
TState
Actually, I'm wrong here, I forget we pass the work item itself as the state! |
Fixed. |
…464) ReadAsyncInternal is correctly passing its token into the two call sites where it delegates directly to the underlying stream, but in one place it calls through ReadBufferAsync, which is currently not defined to take a token. Fix that, and pass the token through. Signed-off-by: dotnet-bot <[email protected]>
…464) ReadAsyncInternal is correctly passing its token into the two call sites where it delegates directly to the underlying stream, but in one place it calls through ReadBufferAsync, which is currently not defined to take a token. Fix that, and pass the token through. Signed-off-by: dotnet-bot <[email protected]>
…464) (dotnet#27501) ReadAsyncInternal is correctly passing its token into the two call sites where it delegates directly to the underlying stream, but in one place it calls through ReadBufferAsync, which is currently not defined to take a token. Fix that, and pass the token through. Signed-off-by: dotnet-bot <[email protected]>
In .NET Core 2.1 we've added this new overload:
We should change it to instead be:
This has several benefits:
Action<object>
withobject state
can be used, without a mismatch of delegate signatures.Action<object>
is now commonly used in these situations.We should fix this before we ship 2.1.
cc: @benaadams, @davidfowl, @kouvel
The text was updated successfully, but these errors were encountered: