Skip to content

Reduce memory allocations for non-streaming async requests - #7323

Merged
alextwoods merged 1 commit into
masterfrom
alexwoo/optimize_simple_http_publisher
Aug 27, 2026
Merged

Reduce memory allocations for non-streaming async requests#7323
alextwoods merged 1 commit into
masterfrom
alexwoo/optimize_simple_http_publisher

Conversation

@alextwoods

Copy link
Copy Markdown
Contributor

Reduced memory allocation for non-streaming requests made with async clients by reading the marshalled request body into a single correctly-sized buffer, instead of copying it through a growing intermediate buffer on every attempt

Motivation and Context

Profiling identified that for non-streaming bodies in the async client, we were unessecarily copy/allocating more than a full copy (because of the growing intermeidate buffer) of the request body in the SimpleHttpContentPublisher. We generally have content-length available and can use that to right-size a buffer. This change doesn't avoid the full copy (that would require larger interface updates), but at least it avoids allocating a growing intermediate buffer.

Note this is an async client only problem, sync doesn't use this path.

Modifications

Testing

Added new unit tests to cover the full SimpleHttpContentPublisher.

Benchmarks

baseline	scoped-down
tiny — time	22.898 ± 1.829 µs/op	19.221 ± 0.517 µs/op (−16.1%)
tiny — alloc	52,829 ± 322 B/op	48,776 ± 97 B/op (−7.7%)
350 KB — time	468.343 ± 21.902 µs/op	409.561 ± 13.794 µs/op (−12.5%)
350 KB — alloc	2,195,108 ± 2,071 B/op	1,145,135 ± 334 B/op (−47.8%)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.

License

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

@alextwoods
alextwoods requested a review from a team as a code owner August 26, 2026 21:47
@alextwoods alextwoods added the perf-improvement Label for PRs that contain performance improvement changes. label Aug 26, 2026
@alextwoods
alextwoods requested a review from S-Saranya1 August 27, 2026 00:22
@alextwoods
alextwoods enabled auto-merge August 27, 2026 21:06
@alextwoods
alextwoods added this pull request to the merge queue Aug 27, 2026
Merged via the queue into master with commit 1fa357a Aug 27, 2026
18 checks passed
@github-actions

Copy link
Copy Markdown

This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

perf-improvement Label for PRs that contain performance improvement changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants