Skip to content

Conversation

@captainsafia
Copy link
Member

Closes #41705

Validation

app.MapGet("/", () => "Look ma! No params.")
    .AddFilter((c, n) => n(c));
> 1..1000 | % { curl http://localhost:5000 }

Before Change

Type Allocations
+ System.Object[] 1,698
| - System.Object[0] 1,003

After Change

Type Allocations
+ System.Object[] 702
| - System.Object[0] 2

@ghost ghost added the area-runtime label May 18, 2022
@captainsafia captainsafia marked this pull request as ready for review May 18, 2022 22:53
@captainsafia captainsafia merged commit 0fc8f4b into dotnet:main May 18, 2022
@ghost ghost added this to the 7.0-preview5 milestone May 18, 2022
// non-generic implementation of RouteHandlerInvocationContext.
Expression paramArray = factoryContext.BoxedArgs.Length > 0
? Expression.NewArrayInit(typeof(object), factoryContext.BoxedArgs)
: Expression.Call(ArrayEmptyMethod.MakeGenericMethod(new Type[] { typeof(object) }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't MakeGenericMethod be hoisted to the stored MethodInfo so we use the same one for every filter factory?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can cache this one for object too since we're not using the open generic to close over other arrays yes.

@davidfowl davidfowl added the Perf label Aug 26, 2022
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions Perf

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filters that don't have any parameters shouldn't allocate an empty array

4 participants