From 227c6b813399158c45ef5d1b1d42427f3e539d7e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 16 Mar 2018 09:41:34 -0700 Subject: [PATCH] Use the array unpacker instead of the Stream unpacker (#1619) - This reduces allocations and improves throughout of msgpack --- .../Internal/Protocol/MessagePackHubProtocol.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.SignalR.Protocols.MsgPack/Internal/Protocol/MessagePackHubProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Protocols.MsgPack/Internal/Protocol/MessagePackHubProtocol.cs index bf5c45f537..f3aafe53ac 100644 --- a/src/Microsoft.AspNetCore.SignalR.Protocols.MsgPack/Internal/Protocol/MessagePackHubProtocol.cs +++ b/src/Microsoft.AspNetCore.SignalR.Protocols.MsgPack/Internal/Protocol/MessagePackHubProtocol.cs @@ -41,16 +41,13 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol { while (BinaryMessageParser.TryParseMessage(ref input, out var payload)) { - using (var memoryStream = new MemoryStream(payload.ToArray())) - { - messages.Add(ParseMessage(memoryStream, binder)); - } + messages.Add(ParseMessage(payload.ToArray(), binder)); } return messages.Count > 0; } - private static HubMessage ParseMessage(Stream input, IInvocationBinder binder) + private static HubMessage ParseMessage(byte[] input, IInvocationBinder binder) { using (var unpacker = Unpacker.Create(input)) {