Repository navigation
perf(http): split clear-text HTTP autodetect connection task - #33887
Conversation
fibibot
left a comment
There was a problem hiding this comment.
Substance reads correct
The optimization is real: the old serve_http2_autodetect future bakes the storage for both serve_http2_unconditional and serve_http11_unconditional into one state machine, so every clear-text connection allocated max(http1_size, http2_size) even when the prefix never matched HTTP/2. By spawning the chosen branch as its own task post-prefix-detection, only the chosen future's storage is allocated.
Walked the changes
- Cancellation semantics preserved:
connection_cancel_handleis moved into the inner spawn'stry_or_cancel;_for_outeris the clone wrapping the outer task. Both share the same underlying CancelHandle, so an external.cancel()(e.g., viaop_http_cancel→connection_cancel_handle()) fires both. ✓ - Move analysis on
if matches { ... } else { ... }: each branch consumesconnection_cancel_handle/svc/listen_cancel_handle/ioonce; only one branch executes, so the borrow checker accepts it. (CI confirms —buildshards all green.) ✓ wait_for_connection=falsepath (the accept loop at line 1305): outer returnsOk(())immediately after spawning inner. Outer JoinHandle is dropped without await — tokio detaches, doesn't cancel. Inner runs to completion. ✓wait_for_connection=truepath (op_http_serve_onat line 1356): outer awaitsjoin_handle.await?. Two?'s collapsed into one — first unwrapsJoinError, second propagatesHttpNextError. Result type matches outer closure'sResult<(), HttpNextError>. ✓- TLS path unchanged:
serve_http2_autodetectis still called inline byserve_httpsat line 1054 — that path keeps the old structure (TLS-buffer overhead dwarfs the future-size delta, so the optimization isn't worth duplicating there).
No concerns from me on the substance. One drive-by observation: serve_https could have the same split applied as a follow-up if the same allocation is showing up there too, but that's well out of scope for this PR.
CI status
92/(135) success, 12 in_progress (mostly the Windows-aarch64 shards plus a few late-finishing macos/linux jobs), 0 fail, 1 skip (publish canary). Holding at COMMENT pending CI completion per the never-APPROVE-while-pending rule. I'll re-confirm with APPROVE once Windows-aarch64 lands clean.
…d#33887) To avoid allocating the http2 future when it's only http1
To avoid allocating the http2 future when it's only http1