-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Avoid delegate allocation in NamedPipeClientStream.ConnectAsync #68752
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
Conversation
We still need to allocate an object for the closed-over state, but we can avoid the per-call delegate allocation.
|
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsWe still need to allocate an object for the closed-over state, but we can avoid the per-call delegate allocation.
|
danmoseley
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we / should we do a pass for other places that could benefit from translating to a static lambda? Eg., at random
RequestQueue<HttpConnection>.QueueItem queueItem = _http11RequestQueue.PeekNextRequestForConnectionAttempt();
Task.Run(() => AddHttp11ConnectionAsync(queueItem));|
I actually don't have a good intuition for these things, and why the compiler or runtime can't do this transformation when possible. |
|
| int startTime = Environment.TickCount; // We need to measure time here, not in the lambda | ||
| return Task.Run(() => ConnectInternal(timeout, cancellationToken, startTime), cancellationToken); | ||
|
|
||
| return Task.Factory.StartNew(static state => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Task.Factory.StartNew -- so you could pass DenyChildAttach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's just because Task.Factory.StartNew accepts a state object, whereas Task.Run doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because Task.Factory.StartNew accepts a state object
Right
|
Ha, I hadn't seen that. Is Task.Run without 'static' the code smell? eg runtime/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpStreamAsyncResult.cs Line 76 in 3535e07
edit: never mind, there's clearly already a delegate allocated in that case. OK, I don't see significant other cases then. |
We still need to allocate an object for the closed-over state, but we can avoid the per-call delegate allocation.