Skip to content

Add Write(ReadOnlySpan<byte>) override to FileBufferingWriteStream - #69068

Open
SimonCropp wants to merge 2 commits into
dotnet:mainfrom
SimonCropp:webutilities/filebufferingwritestream-span
Open

Add Write(ReadOnlySpan<byte>) override to FileBufferingWriteStream#69068
SimonCropp wants to merge 2 commits into
dotnet:mainfrom
SimonCropp:webutilities/filebufferingwritestream-span

Conversation

@SimonCropp

@SimonCropp SimonCropp commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Add Write(ReadOnlySpan) override to FileBufferingWriteStream

Description

Span-based writers such as System.Text.Json previously went through the base Stream fallback, which rents a pooled array and copies before the array overload copies again into the paged buffer. Move the write implementation onto the span overload, have the array overload delegate to it, and give PagedByteBuffer a ReadOnlySpan Add that the ReadOnlyMemory overload forwards to.

Span-based writers such as System.Text.Json previously went through the
base Stream fallback, which rents a pooled array and copies before the
array overload copies again into the paged buffer. Move the write
implementation onto the span overload, have the array overload delegate
to it, and give PagedByteBuffer a ReadOnlySpan<byte> Add that the
ReadOnlyMemory<byte> overload forwards to.
Copilot AI lite review requested due to automatic review settings September 4, 2026 23:41
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Sep 4, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @SimonCropp. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@github-actions github-actions Bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Sep 4, 2026

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.

🟢 Approval recommended

The changes are small, behavior-preserving, covered indirectly by existing tests via the array/memory overload paths, and primarily improve performance for span-based writers.

Pull request overview

This PR improves FileBufferingWriteStream write performance for span-based callers by overriding Stream.Write(ReadOnlySpan<byte>), so span writers (e.g., System.Text.Json) avoid the base Stream fallback path that rents/copies via pooled arrays.

Changes:

  • Add FileBufferingWriteStream.Write(ReadOnlySpan<byte>) and route the byte[] overload to it.
  • Add PagedByteBuffer.Add(ReadOnlySpan<byte>) and have the ReadOnlyMemory<byte> overload delegate to it.
  • Update PublicAPI.Unshipped.txt to track the new public override.
File summaries
File Description
src/Http/WebUtilities/src/PublicAPI.Unshipped.txt Records the added Write(ReadOnlySpan<byte>) override on FileBufferingWriteStream as unshipped public API.
src/Http/WebUtilities/src/PagedByteBuffer.cs Adds a span-based Add overload and forwards ReadOnlyMemory<byte> writes to it to reduce copying overhead.
src/Http/WebUtilities/src/FileBufferingWriteStream.cs Implements the span-based write override and reuses it from the array overload for improved perf and consistent behavior.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants