Skip to content

Cache boundary delimiter strings in MultipartContent#124963

Open
cincuranet wants to merge 5 commits intodotnet:mainfrom
cincuranet:boundary
Open

Cache boundary delimiter strings in MultipartContent#124963
cincuranet wants to merge 5 commits intodotnet:mainfrom
cincuranet:boundary

Conversation

@cincuranet
Copy link
Contributor

@cincuranet cincuranet commented Feb 27, 2026

Pre-compute and cache _startBoundary and _endBoundary strings in the constructor to avoid repeated string concatenation on every call to SerializeToStream, SerializeToStreamAsync, and CreateContentReadStream. Also reduces the writes in SerializeHeadersToStream from 3 calls to 2.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

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 System.Net.Http.MultipartContent boundary handling by caching the commonly-used boundary delimiter strings to reduce per-serialization string construction overhead and slightly reduce write calls during header serialization.

Changes:

  • Precompute and store _startBoundary and _endBoundary strings in the MultipartContent constructor.
  • Reuse the cached boundary strings in SerializeToStream, SerializeToStreamAsyncCore, and CreateContentReadStreamAsyncCore.
  • Reduce divider writes in SerializeHeadersToStream by writing the cached boundary string instead of piecemeal fragments.

Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings March 6, 2026 10:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@cincuranet cincuranet requested a review from ManickaP March 6, 2026 11:39
@cincuranet cincuranet marked this pull request as ready for review March 6, 2026 11:41
Copilot AI review requested due to automatic review settings March 6, 2026 11:41
Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants