Skip to content

Fix benchmark request-size measurement and buffer disposal for PooledContentStream marshallers#4449

Open
muhammad-othman wants to merge 1 commit into
developmentfrom
muhamoth/DOTNET-8587-optimize-cbor-serilaization-benchmarks-changes
Open

Fix benchmark request-size measurement and buffer disposal for PooledContentStream marshallers#4449
muhammad-othman wants to merge 1 commit into
developmentfrom
muhamoth/DOTNET-8587-optimize-cbor-serilaization-benchmarks-changes

Conversation

@muhammad-othman

@muhammad-othman muhammad-othman commented Jun 24, 2026

Copy link
Copy Markdown
Member

Description

Updates the serde and CBOR performance benchmarks to read the marshalled request body size correctly and to dispose each marshalled request, matching the production pipeline.

Request body size is now read from whichever field the marshaller populated, so the benchmarks work whether or not a marshaller writes its body into a pooled buffer.

Each marshalled request is now disposed after measuring. The production pipeline disposes the request after marshalling so when the body is backed by a pooled buffer, that returns the buffer and keeps the pool warm. Without it, every iteration forced a fresh allocation and [MemoryDiagnoser] overstated the real per-request cost.

Motivation and Context

DOTNET-8581

Testing

Ran the updated benchmarks.

Dry-runs

  • DotNet Dry-run ID: 5a906d62-708f-48cb-9706-75ab2910956f
    • Pending
    • Completed successfully
    • Failed
  • PowerShell Dry-run ID: cefb9ddf-20f2-4f2c-a1c8-dd414f3199c6
    • Pending
    • Completed successfully
    • Failed

Breaking Changes Assessment

  1. Identify all breaking changes including the following details:
    • What functionality was changed?
    • How will this impact customers?
    • Why does this need to be a breaking change and what are the most notable non-breaking alternatives?
    • Are best practices being followed?
    • How have you tested this breaking change?
  2. Has a senior/+ engineer been assigned to review this PR?

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

@muhammad-othman muhammad-othman requested review from a team as code owners June 24, 2026 18:54
@muhammad-othman muhammad-othman requested review from dscpinheiro and peterrsongg and removed request for a team June 24, 2026 18:54
@dscpinheiro dscpinheiro requested review from boblodgett and removed request for peterrsongg June 24, 2026 19:06
@muhammad-othman muhammad-othman force-pushed the muhamoth/DOTNET-8587-optimize-cbor-serilaization-benchmarks-changes branch from 76ee5f5 to ecb137a Compare June 24, 2026 21:58
@dscpinheiro dscpinheiro requested a review from Copilot June 24, 2026 22:16

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

Updates the performance benchmark runners to measure marshalled request payload sizes correctly across marshallers that use either legacy byte[] Content or pooled-buffer-backed PooledContentStream, and to dispose marshalled requests to better mirror the production pipeline and avoid skewed allocation measurements.

Changes:

  • Added a shared helper to read request body size from either Content or PooledContentStream and dispose the marshalled request.
  • Updated SerdeBenchmarks marshalling benchmarks to return the request body size and dispose each marshalled request.
  • Updated CBOR performance benchmark utilities to read body size from PooledContentStream (and added a missing using for event-stream headers).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sdk/test/Performance/SerdeBenchmarks/SerdeBenchmarksRunner/TestDataHelpers.cs Adds helper to measure marshalled request size and dispose marshalled IRequest.
sdk/test/Performance/SerdeBenchmarks/SerdeBenchmarksRunner/RpcV2CborBenchmarks.cs Updates marshalling benchmarks to return size via helper and dispose requests.
sdk/test/Performance/SerdeBenchmarks/SerdeBenchmarksRunner/RestXmlBenchmarks.cs Updates REST-XML request benchmarks to return size via helper and dispose requests.
sdk/test/Performance/SerdeBenchmarks/SerdeBenchmarksRunner/RestJson1Benchmarks.cs Updates REST-JSON request benchmarks to return size via helper and dispose requests.
sdk/test/Performance/SerdeBenchmarks/SerdeBenchmarksRunner/AwsQueryBenchmarks.cs Updates AWS Query request benchmarks to return size via helper and dispose requests.
sdk/test/Performance/SerdeBenchmarks/SerdeBenchmarksRunner/AwsJson10Benchmarks.cs Updates AWS JSON 1.0 request benchmarks to return size via helper and dispose requests.
sdk/test/Performance/CborPerformanceBenchmarks/CborPerformanceBenchmarksRunner/Utils.cs Adds GetContentLength(IRequest) to read from pooled content streams or legacy Content.
sdk/test/Performance/CborPerformanceBenchmarks/CborPerformanceBenchmarksRunner/FakeWebResponseData.cs Adds required Amazon.Runtime.EventStreams using for IEventStreamHeader.
sdk/test/Performance/CborPerformanceBenchmarks/CborPerformanceBenchmarksRunner/BaseBenchmarks.cs Switches request-size measurement to Utils.GetContentLength(...).
sdk/test/Performance/CborPerformanceBenchmarks/CborPerformanceBenchmarksRunner/BaseDoubleBenchmarks.cs Switches request-size measurement to Utils.GetContentLength(...) for the second benchmark slot.

Comment on lines +34 to +43
public static long GetContentLengthAndDispose(IRequest request)
{
try
{
#if !NETFRAMEWORK
if (request.ContentStream is PooledContentStream pooled)
return pooled.Content.Length;
#endif
return request.Content?.Length ?? 0;
}
Comment on lines 43 to 47
[GlobalCleanup(Target = nameof(Marshall))]
public virtual void AfterMarshall()
{
RequestSizeBytes = Math.Max(RequestSizeBytes, MarshalledRequest.Content.Length);
RequestSizeBytes = Math.Max(RequestSizeBytes, Utils.GetContentLength(MarshalledRequest));

Comment on lines 30 to 34
[GlobalCleanup(Target = nameof(Marshall2))]
public virtual void AfterMarshall2()
{
RequestSizeBytes2 = Math.Max(RequestSizeBytes2, MarshalledRequest2.Content.Length);
RequestSizeBytes2 = Math.Max(RequestSizeBytes2, Utils.GetContentLength(MarshalledRequest2));

@muhammad-othman muhammad-othman force-pushed the muhamoth/DOTNET-8587-optimize-cbor-serilaization-benchmarks-changes branch from ecb137a to b4e8f15 Compare June 24, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants