Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Only get Thread.CurrentThread once in PerformIOCompletionCallback#21320

Closed
benaadams wants to merge 2 commits intodotnet:masterfrom
benaadams:PerformIOCompletionCallback
Closed

Only get Thread.CurrentThread once in PerformIOCompletionCallback#21320
benaadams wants to merge 2 commits intodotnet:masterfrom
benaadams:PerformIOCompletionCallback

Conversation

@benaadams
Copy link
Member

@benaadams benaadams commented Dec 1, 2018

Accessing Thread.CurrentThread on each pass of the loop (via ExecutionContext.RunInternal) is a significant contributor of PerformIOCompletionCallback (when the callback is fast)

image

This can be cached and reused for the loop in the same way ThreadPool.Dispatch does.

Am assuming it doesn't need the exception handling EC restore semantics that ExecutionContext.RunInternal provides as its just throwing the exception into the wind (as per ThreadPool.Dispatch)

/cc @stephentoub not sure if this is spilling out of ExecutionContext too much?

@stephentoub
Copy link
Member

not sure if this is spilling out of ExecutionContext too much?

That's my concern. Since @kouvel merged your other PR that did something similar with the worker dispatch loop, he can make a call on this, too.

What impact does this have on throughput?

@benaadams
Copy link
Member Author

Hmm... let me look at this again _IOCompletionCallback is only created on this line

ExecutionContext ec = ExecutionContext.Capture();
_callback = (ec != null && !ec.IsDefault) ? new _IOCompletionCallback(iocb, ec) : (object)iocb;

and the contexts involved should only be default, so a _IOCompletionCallback shouldn't be created and it should run directly 🤔

@benaadams
Copy link
Member Author

Was changed in #18360 to also skip saving the context for default context, but should be running on that version so the EC Run is coming from elsewhere (though that could be an issue as neither execution is guaranteed to be on a clean context; nor are any context changes undone that are made in the callback; for both unsafe or Default)

@benaadams
Copy link
Member Author

Opened #21327 instead as I don't think its currently doing the correct thing

@benaadams benaadams deleted the PerformIOCompletionCallback branch December 2, 2018 00:44
@benaadams
Copy link
Member Author

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants