Skip to content

Fast path for HTTP/2 and HTTP/3 :path validation - #70184

Open
davidfowl wants to merge 2 commits into
mainfrom
perf/kestrel-h2h3-path-validation
Open

davidfowl wants to merge 2 commits into
mainfrom
perf/kestrel-h2h3-path-validation

Conversation

@davidfowl

@davidfowl davidfowl commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Fast path for HTTP/2 and HTTP/3 :path validation

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Description

Avoid narrowing :path to bytes and calling DecodePath for clean HTTP/2 and HTTP/3 paths. A shared PathDecoder.TryGetUnmodifiedPath handles paths without percent escapes or dot segments and with only 0x20..0x7E characters (the same range accepted by the current-main narrowing loop). Without a query it reuses RawTarget; with a query it creates the path substring. All other paths retain existing validation, escaping, normalization and protocol-specific errors. This changes no public API.

Benchmark

Http2StreamHeadersBenchmark resets and processes eight request headers, then calls TryParseRequest. BenchmarkDotNet on the same machine and .NET 12 runtime, Release, against current main b5afc478ce and this rebased branch. The default throughput job (separate A/B runs) yielded:

Path main PR Difference Allocated
/ 167.0 ns 164.2 ns -1.7% (near noise) unchanged, 0 B
/api/products/12345 182.8 ns 166.3 ns -9.0% unchanged, 0 B
/shop/category/electronics/laptops/item-12345?ref=homepage&utm_source=newsletter 230.1 ns 211.3 ns -8.2% unchanged, 208 B

A second ShortRun job in the same executions gave 161.9→169.3 ns (/), 186.6→167.0 ns (short path), 228.7→200.2 ns (query path). The root case is inconclusive; the two longer paths improve in both jobs. These are HTTP/2 measurements; HTTP/3 is behavior-tested but not independently benchmarked.

Tests

The rebased in-memory HTTP/2+HTTP/3 path tests check raw target, path and query for clean paths, /.b, dot segments, percent escapes, query strings and printable-ASCII boundary, and assert rejection for control, DEL and non-ASCII characters with and without a query. Focused test run: 64 passed, 0 failed. Kestrel InMemory.FunctionalTests project builds with 0 warnings and 0 errors.

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

Copilot AI balanced review requested due to automatic review settings October 31, 2026 15:39
@github-actions github-actions Bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Oct 31, 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

There are no active review issues for the HTTP/2 and HTTP/3 path-validation changes.

No open issues 🎉

What changed in this PR

Optimizes Kestrel’s HTTP/2 and HTTP/3 :path validation by skipping byte conversion and decoding for common paths without percent encoding or dot segments, while retaining the existing fallback.

Changes:

  • Adds matching fast paths for HTTP/2 and HTTP/3, with separate validation for paths with and without queries.
  • Extends functional tests for plain paths, normalization, encoding, and invalid characters.
  • Adds a pooled HTTP/2 stream benchmark covering header processing and request validation.
File Description
src/​Servers/​Kestrel/​test/​InMemory.FunctionalTests/​Http3/​Http3StreamTests.cs Adds plain-path and query-bearing decoding and normalization cases.
src/​Servers/​Kestrel/​test/​InMemory.FunctionalTests/​Http2/​Http2StreamTests.cs Adds path cases and invalid-character rejection coverage with a query.
src/​Servers/​Kestrel/​perf/​Microbenchmarks/​Http2/​Http2StreamHeadersBenchmark.cs Benchmarks HTTP/2 header processing across three request targets.
src/​Servers/​Kestrel/​Core/​src/​Internal/​Http3/​Http3Stream.cs Adds the HTTP/3 path-validation fast path.
src/​Servers/​Kestrel/​Core/​src/​Internal/​Http2/​Http2Stream.cs Adds the equivalent HTTP/2 path-validation fast path.

Review effort: Balanced

davidfowl commented Oct 31, 2026 •

Copy link
Copy Markdown
Member Author

Retriggered CI with an empty commit (873e2af). The failures on 5e625ab look unrelated to this change:

  • aspnetcore-components-e2e (Mono server): ServerRoutingTest.NavigationLock_CanBlockExternalNavigation failed. Build Analysis gives it a 26.68% failure rate, and Avoid closure allocations and lock-all Count when adding a SignalR connection to a group #70185 (a SignalR-only change) fails the same leg. It's a Blazor browser navigation test over HTTP/1.1 and doesn't touch the HTTP/2 or HTTP/3 :path code.
  • aspnetcore-ci (Monitor Helix Jobs): Build Analysis lists no failing test for it. I can't open the Helix logs from here, so this part is only partly confirmed. To rule out this change, I ran interleaved A/B runs of the Kestrel InMemory Http2 tests locally (10 rounds each, alternating between builds of the base commit 4f556f7 and this branch). Both builds hit the same intermittent failures in timing and stream-state tests, such as RST_STREAM_IncompleteRequest_AdditionalTrailerFrames_ConnectionAborted, AbortedStream_ResetsAndDrainsRequest_* and OnDynamicIndexedHeader_NewlineCharactersInValue_ThrowsConnectionError. At least one test failed in 5 of 10 rounds on base and 7 of 10 on this branch, which is within noise on this loaded machine. None of the failing tests involves :path validation. The 13 local failures in Core.Tests are IPv6 tests and fail because this machine has no IPv6.

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

@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 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member Author

Merge assessment (Nov 29)

Verdict: Do not merge this head. It conflicts with current main and the Nov 26 path-validation change on main makes the prior encoding/behavior parity claim inapplicable to a straightforward rebase. The author acknowledged both open maintainer requests on Nov 29, but no rebase or code fix has been pushed. The old green checks and H2 benchmark cannot validate a revised implementation.

Dimension Assessment
Size S: 5 files, +166/−0 total; +46 production lines duplicated across HTTP/2 and HTTP/3, plus tests and an H2 microbenchmark.
Impact Potentially high: three-round H2 Http2StreamHeadersBenchmark shows about −4% (/), −8% (short path), and −13% (long path with query); allocations unchanged. HTTP/3 was not benchmarked. These measurements apply to the old-base code, not a rebased fix.
Risk High: both streams validate request :path on every H2/H3 request. A Nov 26 main commit changed the narrowing-loop guard from ch > byte.MaxValue to `ch < 0x20
Tests New path normalization and query cases for both protocols, plus an H2 out-of-byte-range query case. They predate main's stricter range tests and do not establish parity for characters outside 0x20..0x7E that the proposed shortcut can accept.
Review No submitted approval: halter73 COMMENTED with two still-open requests (rebase and update query assertions after #70578; extract the duplicate fast path into PathDecoder). The author acknowledged the rebase/test request and the shared-helper request on Nov 29 without pushing fixes. The issue's /review comment is not a submitted approval.
CI Existing head 873e2afc4931 passed Oct 31 aspnetcore-ci and Helix, but this is an old-base success; no checks validate the conflicting branch rebased onto current main.
Complexity The same fast-path block is duplicated in two stream types. Extraction into PathDecoder and compatibility with the current guard require changes and remeasurement.
Reversibility The original change is additive, but reverting after integration would remove a hot-path optimization; a shared helper would alter the scope of a revert.
Security Not assessed under repository review guidance.
Encoding parity Not established against current main. The no-query shortcut accepts every char up to 0xFF; the query shortcut accepts ASCII, including control characters and 0x7F. Both can return before the current main loop rejects values outside 0x20..0x7E. The previous assessment's parity statement applied only to the Oct 31 base.
Behavior/API No public signature change. As written, simply rebasing the shortcut above the current loop would allow some :path values that current main rejects. This is a source-level comparison, not a run of a rebased build.

Reasons to merge: The original three BDN rounds show a substantial H2 hot-path gain without additional allocations; accepted clean-path requests should benefit on both protocols once parity is preserved.

Reasons not to merge yet: Current-main changes overlap the shortcut and tests, GitHub reports a conflict, and a direct rebase would bypass the tightened character-range check for some paths. Both reviewer requests remain open; the benchmark covers H2 only and the exact-head CI does not exercise a revised implementation.

What would change this verdict: Rebase and preserve the current 0x20..0x7E path rule in any shortcut, with targeted H2/H3 parity tests for out-of-range characters with and without queries; update the #70578 query assertions, share the fast path as requested, resolve both threads, obtain maintainer approval, rerun relevant tests and H2/H3 benchmarks against current main, and get green CI on the revised head.

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

@davidfowl davidfowl added the agent:working An AI agent is actively working on this issue/PR label Nov 29, 2026 — with Copilot SWE Agent

davidfowl commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

ASP.NET Core Perf 2 finished triaging and acknowledging this PR’s reviewer feedback; code fixes remain pending.

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

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

davidfowl commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

ASP.NET Core Perf 2 finished the review fixes; the published branch is awaiting CI and maintainer review.

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

davidfowl and others added 2 commits November 29, 2026 17:38
Skip narrowing the :path value to bytes and running PathDecoder when the path
has no percent-encoding and no dot segments. Inputs that don't match the fast
path, including all invalid ones, use the existing code.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the HTTP/3 import set minimal and cover the printable ASCII boundary with and without a query.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@davidfowl
davidfowl force-pushed the perf/kestrel-h2h3-path-validation branch from 873e2af to f28560b Compare November 29, 2026 17:48
@davidfowl davidfowl removed the agent:working An AI agent is actively working on this issue/PR label Nov 29, 2026

This branch has not been deployed

No deployments
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.

4 participants