From 039762c497b9d799ebe1b5313beedf646eb365d8 Mon Sep 17 00:00:00 2001 From: Yishai Galatzer Date: Wed, 25 Jun 2014 11:53:44 -0700 Subject: [PATCH] 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. --- src/Microsoft.AspNet.Mvc.Core/ReflectedActionExecutor.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Core/ReflectedActionExecutor.cs b/src/Microsoft.AspNet.Mvc.Core/ReflectedActionExecutor.cs index e223b5224a..c9d9f568dd 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ReflectedActionExecutor.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ReflectedActionExecutor.cs @@ -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)mInfo.Invoke. // Returning Task enables us to await on the result. - private static async Task CoerceResultToTaskAsync( + // This method is intentionally not using async pattern to keep jit time (on cold start) to a minimum. + private static Task 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)Convert((Task)result) var genericMethodInfo = _convertOfTMethod.MakeGenericMethod(taskValueType); var convertedResult = (Task)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(result); } }