Skip to content

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

@davidfowl

Description

@davidfowl

We should be using Array.Empty<object>() in this situation.

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => {    });
.AddFilter((context, next) =>
{
    return next(context);
});

app.Run();

image

Type Allocations Bytes Average Size (Bytes)
 + System.Object[] 21,987 667,536 30.36
| - System.Object[0] 21,003 504,072 24
Function Name Allocations Bytes Module Name
 + dynamicClass.lambda_method2(00007FFA03556EC0, object, 00007FFA03071310) 21,001 504,024 anonymously hosted dynamicmethods assembly
| + Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext) 21,001 504,024 microsoft.aspnetcore.routing.il
|| + Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext) 21,001 504,024 microsoft.aspnetcore.routing.il
||| + Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke() 21,001 504,024 microsoft.aspnetcore.diagnostics.il
|||| + System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<T>(T) 21,001 504,024 System.Private.CoreLib.il
||||| + Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext) 21,001 504,024 microsoft.aspnetcore.diagnostics.il

cc @captainsafia

Metadata

Metadata

Assignees

Labels

Perfold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions