-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Fix some low hanging allocation fruit #31115
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ internal static class HandshakeHelpers | |
/// <summary> | ||
/// Gets request headers needed process the handshake on the server. | ||
/// </summary> | ||
public static readonly IEnumerable<string> NeededHeaders = new[] | ||
public static readonly string[] NeededHeaders = new[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PS: We should never do this. It's just inefficient and prevents the JIT from optimizing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 I guess it was done to prevent the array from ever being modified. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm gonna have to find all of the code that does this and fix it. Allocation profiles show interesting things. This also tends to happen when we resolve |
||
{ | ||
HeaderNames.Upgrade, | ||
HeaderNames.Connection, | ||
|
@@ -34,7 +34,7 @@ internal static class HandshakeHelpers | |
}; | ||
|
||
// Verify Method, Upgrade, Connection, version, key, etc.. | ||
public static bool CheckSupportedWebSocketRequest(string method, IEnumerable<KeyValuePair<string, string>> headers) | ||
public static bool CheckSupportedWebSocketRequest(string method, List<KeyValuePair<string, string>> headers) | ||
{ | ||
bool validUpgrade = false, validConnection = false, validKey = false, validVersion = false; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
{ | ||
{ | ||
"solution": { | ||
"path": "..\\..\\AspNetCore.sln", | ||
"projects" : [ | ||
"src\\SignalR\\samples\\SignalRSamples\\SignalRSamples.csproj", | ||
"src\\SignalR\\samples\\SocialWeather\\SocialWeather.csproj", | ||
"src\\SignalR\\samples\\ClientSample\\ClientSample.csproj", | ||
"src\\SignalR\\samples\\WebSocketSample\\WebSocketSample.csproj", | ||
"src\\SignalR\\samples\\JwtClientSample\\JwtClientSample.csproj", | ||
"src\\SignalR\\clients\\ts\\FunctionalTests\\SignalR.Client.FunctionalTestApp.csproj", | ||
"projects": [ | ||
"src\\DataProtection\\Abstractions\\src\\Microsoft.AspNetCore.DataProtection.Abstractions.csproj", | ||
"src\\DataProtection\\Cryptography.Internal\\src\\Microsoft.AspNetCore.Cryptography.Internal.csproj", | ||
"src\\DataProtection\\DataProtection\\src\\Microsoft.AspNetCore.DataProtection.csproj", | ||
"src\\FileProviders\\Embedded\\src\\Microsoft.Extensions.FileProviders.Embedded.csproj", | ||
"src\\Hosting\\Abstractions\\src\\Microsoft.AspNetCore.Hosting.Abstractions.csproj", | ||
"src\\Hosting\\Hosting\\src\\Microsoft.AspNetCore.Hosting.csproj", | ||
"src\\Hosting\\Server.Abstractions\\src\\Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj", | ||
"src\\Hosting\\Server.IntegrationTesting\\src\\Microsoft.AspNetCore.Server.IntegrationTesting.csproj", | ||
"src\\Hosting\\TestHost\\src\\Microsoft.AspNetCore.TestHost.csproj", | ||
"src\\Http\\Authentication.Abstractions\\src\\Microsoft.AspNetCore.Authentication.Abstractions.csproj", | ||
"src\\Http\\Authentication.Core\\src\\Microsoft.AspNetCore.Authentication.Core.csproj", | ||
"src\\Http\\Headers\\src\\Microsoft.Net.Http.Headers.csproj", | ||
"src\\Http\\Http.Abstractions\\src\\Microsoft.AspNetCore.Http.Abstractions.csproj", | ||
"src\\Http\\Http.Extensions\\src\\Microsoft.AspNetCore.Http.Extensions.csproj", | ||
"src\\Http\\Http.Features\\src\\Microsoft.AspNetCore.Http.Features.csproj", | ||
"src\\Http\\Http\\src\\Microsoft.AspNetCore.Http.csproj", | ||
"src\\Http\\Metadata\\src\\Microsoft.AspNetCore.Metadata.csproj", | ||
"src\\Http\\Routing.Abstractions\\src\\Microsoft.AspNetCore.Routing.Abstractions.csproj", | ||
"src\\Http\\Routing\\src\\Microsoft.AspNetCore.Routing.csproj", | ||
"src\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj", | ||
"src\\Middleware\\CORS\\src\\Microsoft.AspNetCore.Cors.csproj", | ||
"src\\Middleware\\Diagnostics.Abstractions\\src\\Microsoft.AspNetCore.Diagnostics.Abstractions.csproj", | ||
"src\\Middleware\\Diagnostics\\src\\Microsoft.AspNetCore.Diagnostics.csproj", | ||
"src\\Middleware\\HttpOverrides\\src\\Microsoft.AspNetCore.HttpOverrides.csproj", | ||
"src\\Middleware\\StaticFiles\\src\\Microsoft.AspNetCore.StaticFiles.csproj", | ||
"src\\Middleware\\WebSockets\\src\\Microsoft.AspNetCore.WebSockets.csproj", | ||
"src\\Security\\Authentication\\Cookies\\src\\Microsoft.AspNetCore.Authentication.Cookies.csproj", | ||
"src\\Security\\Authentication\\Core\\src\\Microsoft.AspNetCore.Authentication.csproj", | ||
"src\\Security\\Authentication\\JwtBearer\\src\\Microsoft.AspNetCore.Authentication.JwtBearer.csproj", | ||
"src\\Security\\Authorization\\Core\\src\\Microsoft.AspNetCore.Authorization.csproj", | ||
"src\\Security\\Authorization\\Policy\\src\\Microsoft.AspNetCore.Authorization.Policy.csproj", | ||
"src\\Servers\\Connections.Abstractions\\src\\Microsoft.AspNetCore.Connections.Abstractions.csproj", | ||
"src\\Servers\\IIS\\IISIntegration\\src\\Microsoft.AspNetCore.Server.IISIntegration.csproj", | ||
"src\\Servers\\Kestrel\\Core\\src\\Microsoft.AspNetCore.Server.Kestrel.Core.csproj", | ||
"src\\Servers\\Kestrel\\Kestrel\\src\\Microsoft.AspNetCore.Server.Kestrel.csproj", | ||
"src\\SignalR\\samples\\JwtSample\\JwtSample.csproj", | ||
"src\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj", | ||
"src\\SignalR\\clients\\csharp\\Client.Core\\src\\Microsoft.AspNetCore.SignalR.Client.Core.csproj", | ||
"src\\SignalR\\clients\\csharp\\Client\\src\\Microsoft.AspNetCore.SignalR.Client.csproj", | ||
"src\\SignalR\\clients\\csharp\\Client\\test\\FunctionalTests\\Microsoft.AspNetCore.SignalR.Client.FunctionalTests.csproj", | ||
"src\\SignalR\\clients\\csharp\\Client\\test\\UnitTests\\Microsoft.AspNetCore.SignalR.Client.Tests.csproj", | ||
"src\\SignalR\\clients\\csharp\\Http.Connections.Client\\src\\Microsoft.AspNetCore.Http.Connections.Client.csproj", | ||
"src\\SignalR\\clients\\ts\\FunctionalTests\\SignalR.Client.FunctionalTestApp.csproj", | ||
"src\\SignalR\\common\\Http.Connections.Common\\src\\Microsoft.AspNetCore.Http.Connections.Common.csproj", | ||
"src\\SignalR\\common\\Http.Connections\\src\\Microsoft.AspNetCore.Http.Connections.csproj", | ||
"src\\SignalR\\common\\Http.Connections\\test\\Microsoft.AspNetCore.Http.Connections.Tests.csproj", | ||
"src\\SignalR\\common\\Protocols.Json\\src\\Microsoft.AspNetCore.SignalR.Protocols.Json.csproj", | ||
"src\\SignalR\\common\\Protocols.MessagePack\\src\\Microsoft.AspNetCore.SignalR.Protocols.MessagePack.csproj", | ||
"src\\SignalR\\common\\Protocols.NewtonsoftJson\\src\\Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson.csproj", | ||
"src\\SignalR\\common\\SignalR.Common\\src\\Microsoft.AspNetCore.SignalR.Common.csproj", | ||
"src\\SignalR\\common\\SignalR.Common\\test\\Microsoft.AspNetCore.SignalR.Common.Tests.csproj", | ||
"src\\SignalR\\common\\testassets\\Tests.Utils\\Microsoft.AspNetCore.SignalR.Tests.Utils.csproj", | ||
"src\\SignalR\\perf\\Microbenchmarks\\Microsoft.AspNetCore.SignalR.Microbenchmarks.csproj", | ||
"src\\SignalR\\samples\\ClientSample\\ClientSample.csproj", | ||
"src\\SignalR\\samples\\JwtClientSample\\JwtClientSample.csproj", | ||
"src\\SignalR\\samples\\JwtSample\\JwtSample.csproj", | ||
"src\\SignalR\\samples\\SignalRSamples\\SignalRSamples.csproj", | ||
"src\\SignalR\\samples\\SocialWeather\\SocialWeather.csproj", | ||
"src\\SignalR\\samples\\WebSocketSample\\WebSocketSample.csproj", | ||
"src\\SignalR\\server\\Core\\src\\Microsoft.AspNetCore.SignalR.Core.csproj", | ||
"src\\SignalR\\server\\SignalR\\src\\Microsoft.AspNetCore.SignalR.csproj", | ||
"src\\SignalR\\server\\SignalR\\test\\Microsoft.AspNetCore.SignalR.Tests.csproj", | ||
"src\\SignalR\\common\\Protocols.NewtonsoftJson\\src\\Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson.csproj", | ||
"src\\SignalR\\server\\Specification.Tests\\src\\Microsoft.AspNetCore.SignalR.Specification.Tests.csproj", | ||
"src\\SignalR\\server\\StackExchangeRedis\\src\\Microsoft.AspNetCore.SignalR.StackExchangeRedis.csproj", | ||
"src\\SignalR\\server\\StackExchangeRedis\\test\\Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests.csproj", | ||
"src\\Hosting\\Abstractions\\src\\Microsoft.AspNetCore.Hosting.Abstractions.csproj", | ||
"src\\Http\\Headers\\src\\Microsoft.Net.Http.Headers.csproj", | ||
"src\\Servers\\Connections.Abstractions\\src\\Microsoft.AspNetCore.Connections.Abstractions.csproj", | ||
"src\\Http\\Http.Features\\src\\Microsoft.AspNetCore.Http.Features.csproj", | ||
"src\\Http\\Http.Extensions\\src\\Microsoft.AspNetCore.Http.Extensions.csproj", | ||
"src\\Security\\Authorization\\Core\\src\\Microsoft.AspNetCore.Authorization.csproj", | ||
"src\\Hosting\\Server.Abstractions\\src\\Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj", | ||
"src\\Http\\Authentication.Abstractions\\src\\Microsoft.AspNetCore.Authentication.Abstractions.csproj", | ||
"src\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj", | ||
"src\\DataProtection\\DataProtection\\src\\Microsoft.AspNetCore.DataProtection.csproj", | ||
"src\\Middleware\\WebSockets\\src\\Microsoft.AspNetCore.WebSockets.csproj", | ||
"src\\Middleware\\Diagnostics.Abstractions\\src\\Microsoft.AspNetCore.Diagnostics.Abstractions.csproj", | ||
"src\\DataProtection\\Cryptography.Internal\\src\\Microsoft.AspNetCore.Cryptography.Internal.csproj", | ||
"src\\DataProtection\\Abstractions\\src\\Microsoft.AspNetCore.DataProtection.Abstractions.csproj", | ||
"src\\Servers\\Kestrel\\Core\\src\\Microsoft.AspNetCore.Server.Kestrel.Core.csproj", | ||
"src\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj", | ||
"src\\Http\\Routing\\src\\Microsoft.AspNetCore.Routing.csproj", | ||
"src\\Http\\Routing.Abstractions\\src\\Microsoft.AspNetCore.Routing.Abstractions.csproj", | ||
"src\\Security\\Authorization\\Policy\\src\\Microsoft.AspNetCore.Authorization.Policy.csproj", | ||
"src\\SignalR\\clients\\csharp\\Client\\src\\Microsoft.AspNetCore.SignalR.Client.csproj", | ||
"src\\SignalR\\clients\\csharp\\Client.Core\\src\\Microsoft.AspNetCore.SignalR.Client.Core.csproj", | ||
"src\\Middleware\\HttpOverrides\\src\\Microsoft.AspNetCore.HttpOverrides.csproj", | ||
"src\\SignalR\\common\\Protocols.Json\\src\\Microsoft.AspNetCore.SignalR.Protocols.Json.csproj", | ||
"src\\Http\\Metadata\\src\\Microsoft.AspNetCore.Metadata.csproj", | ||
"src\\WebEncoders\\src\\Microsoft.Extensions.WebEncoders.csproj", | ||
"src\\FileProviders\\Embedded\\src\\Microsoft.Extensions.FileProviders.Embedded.csproj" | ||
"src\\WebEncoders\\src\\Microsoft.Extensions.WebEncoders.csproj" | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -542,7 +542,7 @@ private async Task ExecuteApplication(ConnectionDelegate connectionDelegate) | |
|
||
// Jump onto the thread pool thread so blocking user code doesn't block the setup of the | ||
// connection and transport | ||
await AwaitableThreadPool.Yield(); | ||
await Task.Yield(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be equivalent in the default case as there's no sync context or custom task scheduler. The end result is that it won't allocate an additional task as it re-queues the state machine to the thread pool. |
||
|
||
// Running this in an async method turns sync exceptions into async ones | ||
await connectionDelegate(this); | ||
|
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.
PS: We should never do this. It's just inefficient.