Skip to content

Commit 3bacfee

Browse files
authored
Avoid a state machine allocation in EndpointMiddleware (#46271)
If logging is not enabled, we don't have to await the RequestDelegate task
1 parent 4175146 commit 3bacfee

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Http/Routing/src/EndpointMiddleware.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public Task Invoke(HttpContext httpContext)
5050

5151
if (endpoint.RequestDelegate is not null)
5252
{
53+
if (!_logger.IsEnabled(LogLevel.Information))
54+
{
55+
// Avoid the AwaitRequestTask state machine allocation if logging is disabled.
56+
return endpoint.RequestDelegate(httpContext);
57+
}
58+
5359
Log.ExecutingEndpoint(_logger, endpoint);
5460

5561
try

0 commit comments

Comments
 (0)