Remove unnecessary awaits to speed up cold startup time.
The await/async patterns adds a state machine that takes time to jit, in this case the await is not necessary and the code remains simple without adding continuations.
This commit is contained in:
parent
177aadeadf
commit
039762c497
|
|
@ -60,7 +60,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
// This is necessary to enable calling await on the returned task.
|
||||
// i.e we need to write the following var result = await (Task<ActualType>)mInfo.Invoke.
|
||||
// Returning Task<object> enables us to await on the result.
|
||||
private static async Task<object> CoerceResultToTaskAsync(
|
||||
// This method is intentionally not using async pattern to keep jit time (on cold start) to a minimum.
|
||||
private static Task<object> CoerceResultToTaskAsync(
|
||||
object result,
|
||||
Type returnType,
|
||||
string methodName,
|
||||
|
|
@ -74,7 +75,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
if (returnType == typeof(Task))
|
||||
{
|
||||
ThrowIfWrappedTaskInstance(resultAsTask.GetType(), methodName, declaringType);
|
||||
return await CastToObject(resultAsTask);
|
||||
return CastToObject(resultAsTask);
|
||||
}
|
||||
|
||||
var taskValueType = TypeHelper.GetTaskInnerTypeOrNull(returnType);
|
||||
|
|
@ -84,7 +85,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
// constructs: return (Task<object>)Convert<T>((Task<T>)result)
|
||||
var genericMethodInfo = _convertOfTMethod.MakeGenericMethod(taskValueType);
|
||||
var convertedResult = (Task<object>)genericMethodInfo.Invoke(null, new object[] { result });
|
||||
return await convertedResult;
|
||||
return convertedResult;
|
||||
}
|
||||
|
||||
// This will be the case for:
|
||||
|
|
@ -96,7 +97,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
return Task.FromResult<object>(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue