Skip to content

perf(streaming): avoid copying memory stream payloads - #10550

Merged
ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:rb-optimize-hot-path
Aug 12, 2026
Merged

ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:rb-optimize-hot-path

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Aug 12, 2026

Copy link
Copy Markdown
Member

The default memory-stream deserializer materializes every serialized payload with ArraySegment<byte>.ToArray() before deserializing it. This adds an allocation and an O(payload-size) copy for every batch read.

Pass the existing ArraySegment<byte> directly to Orleans' serializer instead. Its segment overload deserializes from the underlying span, preserving offsets and lengths while avoiding the payload clone.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 12, 2026 08:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the in-memory stream provider’s message-body deserialization path by avoiding an unnecessary ArraySegment<byte>.ToArray() allocation/copy, and instead deserializing directly from the existing ArraySegment<byte> using Orleans’ serializer overload.

Changes:

  • Replaced serializer.Deserialize(bodyBytes.ToArray()) with serializer.Deserialize(bodyBytes) to avoid per-payload cloning during batch reads.
Show a summary per file
File Description
src/Orleans.Streaming/MemoryStreams/MemoryMessageBody.cs Switch deserialization to use ArraySegment<byte> directly, eliminating an allocation and O(n) copy per payload.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

@ReubenBond
ReubenBond merged commit 7131781 into dotnet:main Aug 12, 2026
134 of 138 checks passed
@ReubenBond
ReubenBond deleted the rb-optimize-hot-path branch August 12, 2026 14:44
This was referenced Aug 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants