Skip to content

Write Minimal API views directly to the response PipeWriter - #976

Merged
sebastienros merged 2 commits into
mainfrom
sebros/pipewriter-fluid-output
Aug 18, 2026
Merged

Write Minimal API views directly to the response PipeWriter#976
sebastienros merged 2 commits into
mainfrom
sebros/pipewriter-fluid-output

Conversation

@sebastienros

Copy link
Copy Markdown
Owner

Minimal API view responses currently pass through both TextWriterFluidOutput and StreamWriter, adding a redundant character buffer and per-response UTF-8 conversion allocations. This change writes Fluid output directly to HttpResponse.BodyWriter while retaining bounded buffering and streaming behavior.

Changes

  • Add a pooled UTF-8 PipeWriterFluidOutput implementation of IFluidOutput.
  • Preserve encoder state across writes, including surrogate pairs split at buffer boundaries.
  • Flush at OutputBufferSize, honor request cancellation, and leave the ASP.NET response pipe open.
  • Use the new output directly from ActionViewResult.
  • Cover UTF-8 output, buffer growth, automatic flushing, cancellation, and disposal behavior.

Performance

A 20,000-iteration rendering-shaped microbenchmark improved from 27.7 ms and 5,384 B/operation to 18.1 ms and 120 B/operation.

Validation

  • Release build succeeds for net8.0, net9.0, and net10.0.
  • Focused pipe checks cover UTF-8, split surrogate pairs, bounded flushing after buffer growth, and cancellation.
  • The full xUnit suite could not be restored locally because the configured package proxy does not yet contain xunit.v3.mtp-v2 4.0.0.

sebastienros and others added 2 commits August 17, 2026 18:13
Write rendered UTF-8 output directly to HttpResponse.BodyWriter while preserving bounded buffering, cancellation, and split surrogate handling.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6b8b28d8-2e30-4bee-98e3-9286818786be
Add the missing Xunit and BCL using directives in the new PipeWriterFluidOutput tests so the test project compiles on CI.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sebastienros
sebastienros merged commit cb6712e into main Aug 18, 2026
3 checks passed
@sebastienros
sebastienros deleted the sebros/pipewriter-fluid-output branch August 18, 2026 01:31
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.

1 participant