Don't inline GetTaskForResult when await'ing ValueTask
authorStephen Toub <stoub@microsoft.com>
Tue, 31 Oct 2017 01:39:28 +0000 (21:39 -0400)
committerStephen Toub <stoub@microsoft.com>
Tue, 31 Oct 2017 01:46:17 +0000 (21:46 -0400)
commitc791335d30624d1cf2ecd35121e3121f896b19d5
tree087aaf78b336cf06bdc5a07d0105c04e6be5e957
parent9e186c8dc65c71f6c715f7027c976eb12c2f19bb
Don't inline GetTaskForResult when await'ing ValueTask

When await'ing a ValueTask, we should only ever end up calling AwaitUnsafeOnCompleted when the ValueTask wraps a non-null _task; if its _task were null, IsCompleted would have returned true due to treating the _result as the successful result.  However, the value task's AsTask() is currently used via an inlined interface invocation in AwaitUnsafeOnCompleted to get the _task from the ValueTask, and AsTask ends up inlining the _task==null branch that inlines AsyncTaskMethodBuilder'1.GetTaskForResult, which ends up bloating the asm unnecessarily.  We can simply change the interface implementation used by AwaitUnsafeOnCompleted to not inline GetTaskForResult.  In a simple example, this cuts the asm for AwaitUnsafeOnCompleted by ~50%.
src/mscorlib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs
src/mscorlib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs
src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs