Skip to content

[Fusion] Reduce source-response buffer copies - #10581

Merged
tobias-tengler merged 3 commits into
mainfrom
tte/reduce-source-response-stream-copies
Oct 17, 2026
Merged

tobias-tengler merged 3 commits into
mainfrom
tte/reduce-source-response-stream-copies

Conversation

@tobias-tengler

@tobias-tengler tobias-tengler commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Fusion reads source responses with an unknown Content-Length, or a length above 16 KiB, through an intermediate PipeReader buffer before copying them into the request arena. Warm Apollo Federation profiles identify recurring StreamPipeReader and BufferSegment allocations on this path.

Read these bodies directly into the existing arena chunks and parse the filled chunks after EOF. Known positive lengths up to 16 KiB retain their current path; cancellation, transcoding and stream ownership follow the existing response lifetime.

Method Version Mean Ratio Allocated Alloc Ratio
ReadAsResultAsync, known length, 128 B main 838.737 ns 1.00 1192 B 1.00
ReadAsResultAsync, known length, 128 B PR 780.730 ns 0.93 1193 B 1.00
ReadAsResultAsync, unknown length, 4 KiB main 1027.061 ns 1.00 1282 B 1.00
ReadAsResultAsync, unknown length, 4 KiB PR 909.085 ns 0.89 955 B 0.74
ReadAsResultAsync, unknown length, 32 KiB main 3407.502 ns 1.00 1426 B 1.00
ReadAsResultAsync, unknown length, 32 KiB PR 2391.653 ns 0.70 1097.5 B 0.77

Benchmark results above were measured at f7e8b809, before the readability and explicit cancellation-check follow-ups.

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

91.1% of changed lines covered (41/45)

File Covered Changed Patch %
…/Fusion/src/Fusion.Execution/Text/Json/ThrowHelper.cs 0 1 0.0% 🔴
…/AspNetCore/src/Transport.Http/GraphQLHttpResponse.cs 41 44 93.2% 🟡
Uncovered changed lines (JSON)
{
  "sha": "35ad53bb3d2756c9de4406254b98c53f78cc73ad",
  "files": [
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Text/Json/ThrowHelper.cs", "ranges": [[16, 16]] },
    { "path": "src/HotChocolate/AspNetCore/src/Transport.Http/GraphQLHttpResponse.cs", "ranges": [[651, 652], [655, 655]] }
  ]
}

Project coverage: 59.0% (311306/527697 lines)

@tobias-tengler tobias-tengler changed the title Reduce Fusion source-response buffer copies [Fusion] Reduce source-response buffer copies Oct 17, 2026
@tobias-tengler
tobias-tengler marked this pull request as ready for review October 17, 2026 19:54
Copilot AI balanced review requested due to automatic review settings October 17, 2026 19:54

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@tobias-tengler
tobias-tengler merged commit c10683b into main Oct 17, 2026
158 checks passed
@tobias-tengler
tobias-tengler deleted the tte/reduce-source-response-stream-copies branch October 17, 2026 19:58
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.

2 participants