-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Simplify and optimize async parameters in RequestDelegateFactory #42588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Avoid object[] for single BindAsync - Remove redundant state and logic - Cleanup some names and nullability annotations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No deep insight into the code but I noticed this 😄
var arguments = new Expression[factoryContext.ArgumentExpressions.Length + 1]; | ||
arguments[0] = HttpContextExpr; | ||
factoryContext.ArgumentExpressions.CopyTo(arguments, 1); | ||
for (int i = 0; i < methodParameters.Length; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (int i = 0; i < methodParameters.Length; i++) | |
for (var i = 0; i < methodParameters.Length; i++) |
return Expression.New(constructor, arguments); | ||
// For AOT platforms it's not possible to support the closed generic arguments that are based on the | ||
// parameter arguments dynamically (for value types). In that case, fallback to boxing the argument list. | ||
// new RouteHandlerInvocionContext(httpContext, (object)name_local, (object)int_local); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// new RouteHandlerInvocionContext(httpContext, (object)name_local, (object)int_local); | |
// new RouteHandlerInvocationContext(httpContext, (object)name_local, (object)int_local); |
else | ||
{ | ||
methodArgumentTypes = new Type[methodArguments.Length]; | ||
var boxedArgs = new Expression[methodArguments.Length]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: this is only used in the if (!RuntimeFeature.IsDynamicCodeCompiled || !constructorType.IsGenericType)
case, we could slightly restructure to avoid this startup cost
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s what the code did before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hence "super nit"
} | ||
|
||
// new RouteHandlerInvocationContext(httpContext, (object)name_local, (object)int_local); | ||
return fallbackConstruction; | ||
var constructor = constructorType.MakeGenericType(methodArgumentTypes).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).Single(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug.Assert(constructor is not null)
?
if (!successful) | ||
var boundValues = new object?[count]; | ||
|
||
// Looping over arrays is faster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment was more for when we called .ToArray()
on the binders collection, can remove
{ | ||
return valueExpression; | ||
return Expression.Condition(Expression.NotEqual(valueExpression, Expression.Default(parameter.ParameterType)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Show code in a comment?
args[i] = CreateArgument(parameters[i], factoryContext); | ||
var parameter = parameters[i]; | ||
|
||
factoryContext.ParametersAndPropertiesAsParameters.Add(parameter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will change the order the metadata (for parameters from AsParameters
) will be added, right? I don't know if that is a problem and, to be honest, it looks more correct with this change.
As you're taking the big refactor-hammer to things as it is, I wonder if maybe it's also worth moving the other nested types into their own partial files too to get the main file down to under 2k LoC? |
@@ -466,24 +468,22 @@ private static Expression CreateRouteHandlerInvocationContextBase(FactoryContext | |||
_ => typeof(DefaultRouteHandlerInvocationContext) | |||
}; | |||
|
|||
if (constructorType.IsGenericType) | |||
if (!RuntimeFeature.IsDynamicCodeCompiled || !constructorType.IsGenericType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should remove all of these checks now that we're going full source generator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@halter73 Sounds like this needs to be updated after the introduction of RDG. @captainsafia might have thoughts?
@halter73 Thoughts on this PR? If I recall, it still needs a hearty rebase to get it in an up-to-date state. There's also some goodness in here that is probably better to split up into a separate PR like:
|
Thanks for the reminder. I'll work on rebasing this after I update my MapIdentityApi() PR (#47414) in response to API review. |
Uh oh!
There was an error while loading. Please reload this page.