Skip to content
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

Performance microoptimizations #2558

Merged
merged 4 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/Grpc.AspNetCore.Server/Internal/GrpcProtocolHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Grpc.Core;
Expand Down Expand Up @@ -108,7 +109,7 @@ public static byte[] ParseBinaryHeader(string base64)
switch (base64.Length % 4)
{
case 0:
// base64 has the required padding
// base64 has the required padding
decodable = base64;
break;
case 2:
Expand Down Expand Up @@ -208,11 +209,8 @@ public static AuthContext CreateAuthContext(X509Certificate2 clientCertificate)

static void AddProperty(Dictionary<string, List<AuthProperty>> properties, string name, string value)
{
if (!properties.TryGetValue(name, out var values))
{
values = new List<AuthProperty>();
properties[name] = values;
}
ref var values = ref CollectionsMarshal.GetValueRefOrAddDefault(properties, name, out _);
values ??= [];

values.Add(AuthProperty.Create(name, Encoding.UTF8.GetBytes(value)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.AspNetCore.Web/Internal/ServerGrpcWebMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Grpc.AspNetCore.Web.Internal;

internal readonly record struct ServerGrpcWebContext(ServerGrpcWebMode Request, ServerGrpcWebMode Response);

internal enum ServerGrpcWebMode
internal enum ServerGrpcWebMode : byte
{
None,
GrpcWeb,
Expand Down
5 changes: 1 addition & 4 deletions src/Shared/Server/MethodOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ private static void AddCompressionProviders(Dictionary<string, ICompressionProvi
{
foreach (var compressionProvider in compressionProviders)
{
if (!resolvedProviders.ContainsKey(compressionProvider.EncodingName))
{
resolvedProviders.Add(compressionProvider.EncodingName, compressionProvider);
}
resolvedProviders.TryAdd(compressionProvider.EncodingName, compressionProvider);
}
}
}
Expand Down
Loading