Skip to content

Commit

Permalink
Combine ExecutionContext/CapturedContext fields in ManualResetValueTa…
Browse files Browse the repository at this point in the history
…skSourceCore (#82181)

There's currently an _executionContext field and a _capturedContext field.  Both of these are for non-fast-path.  This not only means the struct is larger than is necessary for the common case, it also means when we reset the instance between operations we need to clear an extra field, and it means we have an extra branch on some paths to check both fields.

We can instead combine them into a single field.  We allocate an extra tuple object if there's both an ExecutionContext and a scheduler, but this is exceedingly rare: when used as part of awaits, there will never be an ExecutionContext, so this will only happen in situations where someone is directly using the awaiter's OnCompleted (not UnsafeOnCompleted) method and there's a scheduler and ConfigureAwait(false) wasn't used.  Such a situation not only is rare, it also already has additional overheads.

This also cleans up a bit about how exceptions are handled and moves more logic out of the generic type to avoid code bloat with generic instantiations.
  • Loading branch information
stephentoub authored Mar 2, 2023
1 parent 38b6c82 commit 4da32cd
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 141 deletions.
Loading

0 comments on commit 4da32cd

Please sign in to comment.