From c094b65cd5f72e2bf7da72cffd3980445d44edb2 Mon Sep 17 00:00:00 2001 From: davidfowl <95136+davidfowl@users.noreply.github.com> Date: Fri, 30 Oct 2026 23:11:52 +0000 Subject: [PATCH] Skip streaming-type reflection for primitive SignalR client arguments ReflectionHelper.IsStreamingType calls Type.GetInterfaces, which allocates a new array for every argument on every Send/Invoke/Stream. Primitives, strings, enums, DateTime and decimal can never be streams. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs b/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs index e66190e200a3..ebe006ed0bb7 100644 --- a/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs +++ b/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs @@ -1036,7 +1036,9 @@ private async IAsyncEnumerable CastIAsyncEnumerable(string methodName, obj for (var i = 0; i < args.Length; i++) { var arg = args[i]; - if (arg is not null && ReflectionHelper.IsStreamingType(arg.GetType())) + // Primitives, strings, enums, DateTime and decimal can never be streams, skip the reflection check + // for them since it allocates (Type.GetInterfaces) for every argument on every send. + if (arg is not null && Type.GetTypeCode(arg.GetType()) == TypeCode.Object && ReflectionHelper.IsStreamingType(arg.GetType())) { isStreaming[i] = true; newArgsCount--;