Skip to content

Reuse Http3RawFrame across pooled HTTP/3 streams - #70118

Merged
davidfowl merged 1 commit into
mainfrom
perf/h3-reuse-raw-frame
Nov 16, 2026
Merged

davidfowl merged 1 commit into
mainfrom
perf/h3-reuse-raw-frame

Conversation

@davidfowl

@davidfowl davidfowl commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Reuse Http3RawFrame across pooled HTTP/3 streams

Description

Motivation

Http3Stream.ProcessRequestAsync allocates a new Http3RawFrame for every request, even though HTTP/3 request streams are pooled and reused. HTTP/2 already reuses a single frame per connection.

Change

Http3Stream gets a readonly Http3RawFrame _incomingFrame field. ProcessRequestAsync resets its Type and RemainingLength at the start of each request and then reuses it. TryReadFrame overwrites the frame's state for every frame it reads. The diff is one file, +5/−1.

Benchmarks

Http3ConnectionEmptyBenchmark.MakeRequest from src/Servers/Kestrel/perf/Microbenchmarks, with MemoryDiagnoser.

Environment:

  • BenchmarkDotNet --config perflab (InProcess), --warmupCount 5 --iterationCount 15, plus the JSON exporter to get exact bytes, because the table rounds to KB.
  • AMD EPYC 9V74 with 2 vCPU (container), Ubuntu 24.04, .NET 12.0.0 (12.0.26.52911).
  • Two independent before/after rounds.

BytesAllocatedPerOperation:

ResponseDataLength main run 1 main run 2 PR run 1 PR run 2
0 5,936 B 5,923 B 5,898 B 5,914 B
128 6,086 B 6,216 B 6,017 B 6,065 B
1024 6,990 B 6,982 B 6,896 B 6,951 B

Mean time:

ResponseDataLength main run 1 main run 2 PR run 1 PR run 2
0 22.03 ± 4.74 μs 20.83 ± 5.40 μs 23.47 ± 4.57 μs 35.95 ± 10.59 μs
128 25.09 ± 5.25 μs 22.71 ± 4.49 μs 23.62 ± 7.52 μs 28.27 ± 4.12 μs
1024 24.98 ± 5.93 μs 29.27 ± 5.25 μs 15.46 ± 0.55 μs 26.54 ± 7.58 μs
  • This connection-level benchmark is noisy on a 2 vCPU VM. BenchmarkDotNet's per-operation allocation also includes background noise, but the PR is lower than main in all six pairs.
  • A deterministic allocation measurement (exact bytes per MakeRequest, ResponseDataLength=0) gives main 6052.5 / 6054.4 B/op and the PR 6017.1 / 6015.9 B/op, i.e. −37 B per request.
  • No change in time is claimed; the timing differences are within noise.

Tests

  • InMemory.FunctionalTests (filter Http3): 236 passed, 0 failed.
  • Microsoft.AspNetCore.Server.Kestrel.Core.Tests: everything passed except 13 AddressBinderTests / KestrelServerTests IPv6 tests that fail identically on main, because the test machine has no IPv6.

Benchmark (3 interleaved rounds)

Existing Http3ConnectionEmptyBenchmark.MakeRequest (src/Servers/Kestrel/perf/Microbenchmarks/Http3).

Environment: AMD EPYC 9V74, 2 vCPU (container), Ubuntu 24.04; .NET SDK 12.0.100-alpha.1.26521.103, .NET 12.0.0 (12.0.26.52911); BenchmarkDotNet v0.13.0 --config perflab (InProcess, MemoryDiagnoser), WarmupCount=3, IterationCount=10. "main" is the merge base 4f556f73a6. Both builds use the same benchmark source, and runs were interleaved main, PR, main, PR, main, PR. Each cell shows mean / allocated per operation; allocation figures are exact bytes from the CSV exporter.

Case main r1 PR r1 main r2 PR r2 main r3 PR r3 Δ time (median) Alloc main → PR
Http3ConnectionEmptyBenchmark.MakeRequest [ResponseDataLength=0] 27.15 μs / 5,931 B 25.49 μs / 5,902 B 27.32 μs / 6,317 B 25.21 μs / 6,286 B 29.80 μs / 5,951 B 20.94 μs / 5,904 B -7.7% 5,951 B → 5,904 B
Http3ConnectionEmptyBenchmark.MakeRequest [ResponseDataLength=128] 26.17 μs / 6,481 B 26.20 μs / 6,060 B 28.56 μs / 6,092 B 26.55 μs / 6,447 B 27.98 μs / 6,080 B 32.72 μs / 6,046 B -5.1% 6,092 B → 6,060 B
Http3ConnectionEmptyBenchmark.MakeRequest [ResponseDataLength=1024] 35.28 μs / 6,988 B 30.08 μs / 6,976 B 27.47 μs / 6,984 B 28.30 μs / 6,959 B 26.15 μs / 6,991 B 28.63 μs / 6,966 B +4.2% 6,988 B → 6,966 B
  • Within noise. I'm not claiming a win from this benchmark. Mean time per round varies by ±20% on both sides on this 2-vCPU VM, and the direction of the median change differs across ResponseDataLength values.
  • Allocation: the PR is lower than main in 8 of 9 round pairs, usually by 12–47 B, which is consistent with removing one Http3RawFrame per request. But that's under 1% of the ~6 KB per request, and BenchmarkDotNet's per-operation figure here includes background allocations. One pair (128 B, round 2) went the other way by 355 B.

🤖 Posted by ASP.NET Core Perf 2 (AI Agent)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 16:53
@github-actions github-actions Bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Oct 30, 2026

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.

🟢 Approval recommended

No active review issues are recorded for the HTTP/3 frame reuse change, which reduces per-request allocations.

No open issues 🎉

What changed in this PR

Reduces per-request allocations in Kestrel’s HTTP/3 processing by reusing a frame object across pooled stream requests.

Changes:

  • Adds a readonly Http3RawFrame field to Http3Stream, replacing the per-request allocation.
  • Resets the frame’s type and remaining length before processing each request.
File Description
src/​Servers/​Kestrel/​Core/​src/​Internal/​Http3/​Http3Stream.cs Reuses the incoming frame across pooled requests and resets its state at request start.

Review effort: Balanced

@PureWeen

PureWeen commented Nov 1, 2026

Copy link
Copy Markdown
Member

/review

@davidfowl davidfowl added the agent:working An AI agent is actively working on this issue/PR label Nov 6, 2026 — with Copilot SWE Agent
@davidfowl davidfowl removed the agent:working An AI agent is actively working on this issue/PR label Nov 6, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Nov 13, 2026
@davidfowl
davidfowl merged commit 18f02fc into main Nov 16, 2026
46 checks passed
@davidfowl
davidfowl deleted the perf/h3-reuse-raw-frame branch November 16, 2026 23:10
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants