Skip to content

Cache boundary delimiter strings in MultipartContent - #124963

Merged
cincuranet merged 5 commits into
dotnet:mainfrom
cincuranet:boundary
Mar 9, 2026
Merged

cincuranet merged 5 commits into
dotnet:mainfrom
cincuranet:boundary

Conversation

@cincuranet

@cincuranet cincuranet commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

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 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.

@ManickaP ManickaP left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks.

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

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

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

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

@ManickaP ManickaP left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:shipit:

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

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants