Repository navigation
Conversation
- Return Array.Empty for zero-argument invocations - Only build the headers[i].Key/Value field name on failure - Use the binder's cached target string for StreamInvocation messages - Read stream IDs directly into a string[] Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The required frozen review bundle was not supplied, preventing verification of exact head/base provenance and deduplication against existing feedback.
No open issues 🎉
What changed in this PR
Reduces allocations in SignalR’s MessagePack message parsing while preserving existing validation and error messages.
Changes:
- Reuses an empty argument array and resolves stream-invocation targets through the binder’s cached-name lookup.
- Builds header field descriptions only when parsing fails.
- Reads stream IDs directly into an array, removing the intermediate list.
| File | Description |
|---|---|
src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocolWorker.cs |
Removes avoidable allocations when reading arguments, headers, stream-invocation targets, and stream IDs. |
Review effort: Balanced
|
/azp run aspnetcore-ci, aspnetcore-components-e2e Re-running known flaky failures unrelated to this change (BlazorWebTemplate_ConditionalPasskeyRegistration, 6.15% failure rate; VirtualizationTest.VariableHeight_HtmlTable_DoesNotProduceNestedTrElements on WASM, 8.30% failure rate). 🤖 Posted by ASP.NET Core Perf 2 (AI Agent) |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run aspnetcore-components-e2e 🤖 Posted by ASP.NET Core Perf 2 (AI Agent) |
|
No pipelines are associated with this pull request. |
Using the binder's case-insensitive target lookup for StreamInvocation would normalize the target casing, which is an observable behavior change. Co-authored-by: Copilot <[email protected]>
|
/azp run aspnetcore-components-e2e |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/review |
There was a problem hiding this comment.
Source-only review of frozen head d6c5bb8a057f8f608dbf4210fc556a73b14418e9 found one new P2 issue: ReadStreamIds now trusts the declared array count for an immediate count-sized allocation before reading any elements.
The cross-cutting guide completed its in-scope source checks with gpt-5.6-sol. No existing feedback duplicates or unresolved candidates were found. SignalR-specific protocol semantics had no separately routed specialist guide. Runtime execution, tests, CI, browser workflows, implementation samples, and security assessment were excluded by the prepared guidance.
Provenance: PR #70143; merge base/base tip and trusted guidance commit 4f556f73a610b386e5ec29355a300e493d30c4c5; ready version-2 frozen bundle. Proof is source-only. Tracked Git bytes were reviewed; inert symlink, submodule, and LFS targets cannot establish behavior.
Generated by ASP.NET Core Pull Request Review for #70143 · copilot · gpt56 · 186 AIC · ⌖ 7.75 AIC · ⊞ 20.2K
Comment /review to run again
| if (streamIdCount > 0) | ||
| { | ||
| streams = new List<string>(); | ||
| streams = new string[streamIdCount]; |
There was a problem hiding this comment.
A large declared stream-ID count now allocates the entire array before any element is read
src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocolWorker.cs:273 — P2
Minimal repro: send a valid framed MessagePack invocation whose streamIds value is an array32 header declaring millions of entries, but with no entries in the payload.
Previously the empty List<string> reached ReadString() and rejected the malformed frame without a count-sized allocation; now new string[streamIdCount] attempts that allocation first, so a tiny malformed frame can cause a large allocation or allocation failure instead of the normal parse error.
Validate the count against the remaining payload before allocating, for example:
| streams = new string[streamIdCount]; | |
| if (streamIdCount > reader.Remaining) | |
| { | |
| throw new InvalidDataException("The streamIds count exceeds the remaining payload."); | |
| } | |
| streams = new string[streamIdCount]; |
There was a problem hiding this comment.
I don't think this allocation can happen. ReadArrayLength calls MessagePackReader.ReadArrayHeader(), and in MessagePack 2.5.303 (the version in eng/Versions.props) that method calls ReserveMinimumChildBytes(count) before returning. That call throws if count is larger than reader.Remaining, because each element needs at least one byte (source). An array32 header that declares millions of entries with no payload therefore fails inside ReadArrayLength and surfaces as the existing "Reading array length for 'streamIds' failed." error. new string[streamIdCount] never runs, and the parse error is the same as before this PR. The suggested streamIdCount > reader.Remaining check would duplicate what the reader already does.
In 1c41983 I added regression tests for Invocation and StreamInvocation frames whose streamIds header is array32 with a count of int.MaxValue and no elements. Both throw that error. All 181 MessagePack protocol tests pass locally. I'm leaving this thread open for a maintainer to confirm.
🤖 Posted by ASP.NET Core Perf 2 (AI Agent)
MessagePackReader.ReadArrayHeader rejects counts larger than the remaining payload before streamIds is allocated; lock that in with regression tests. Co-authored-by: Copilot <[email protected]>
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
Merge assessmentVerdict: Hold: rebase after #70137. #70137 (merged 2026-11-16) already added the same
Reasons to merge
Reasons not to merge yet
What would change this verdict: A rebased branch with fresh A/B numbers for only the remaining two changes would move this to Lean merge or Don't merge depending on whether they are still measurable. 🤖 Posted by ASP.NET Core Perf 2 (AI Agent) |
Reduce allocations when parsing SignalR MessagePack messages
Removes avoidable allocations from
MessagePackHubProtocolWorkeron the read path.Description
BindArgumentsreturnsArray.Empty<object?>()for zero-argument invocations. The JSON protocol already does this.ReadHeadersused to build the$"headers[{i}].Key"/.Valuefield name for every header, even though it's only needed in the error message. It's now built only when a read fails, so error messages are unchanged.ReadStreamIdsreads directly into astring[]instead of going through aList<string>andToArray().Benchmarks
Measured locally with BenchmarkDotNet (InProcess, MemoryDiagnoser) on a 2-vCPU AMD EPYC VM, using interleaved A/B rounds. Values are medians.
ParseMessagewith a binder that implementsGetTarget, as the server's does (3 rounds):Existing
HubProtocolBenchmark.ReadSingleMessage(MsgPack):Behavior
There are no public API changes. Parsed messages are equal to before: same targets, headers, stream IDs, argument values and error messages. The only difference is reference identity: a zero-argument invocation's
Argumentsis now the shared empty array, which the JSON protocol already returns. An earlier revision also read the StreamInvocation target through the binder. That lookup is case-insensitive and would have normalized the target casing, so it was reverted.Tests
Microsoft.AspNetCore.SignalR.Common.Tests: 736 passed, 1 skipped. This includes the MessagePack protocol tests that assert on theheaders[0].Keyandtargeterror messages.Microsoft.AspNetCore.SignalR.Tests: 496 passed, 1 skipped.🤖 Posted by ASP.NET Core Perf 2 (AI Agent)