Skip to content

perf(http): split clear-text HTTP autodetect connection task - #33887

Merged
nathanwhit merged 1 commit into
denoland:mainfrom
nathanwhit:split-autodetect-task
May 6, 2026
Merged

nathanwhit merged 1 commit into
denoland:mainfrom
nathanwhit:split-autodetect-task

Conversation

@nathanwhit

Copy link
Copy Markdown
Member

To avoid allocating the http2 future when it's only http1

@nathanwhit
nathanwhit enabled auto-merge (squash) May 6, 2026 22:45

@fibibot fibibot 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.

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_handle is moved into the inner spawn's try_or_cancel; _for_outer is the clone wrapping the outer task. Both share the same underlying CancelHandle, so an external .cancel() (e.g., via op_http_cancel → connection_cancel_handle()) fires both. ✓
  • Move analysis on if matches { ... } else { ... }: each branch consumes connection_cancel_handle / svc / listen_cancel_handle / io once; only one branch executes, so the borrow checker accepts it. (CI confirms — build shards all green.) ✓
  • wait_for_connection=false path (the accept loop at line 1305): outer returns Ok(()) immediately after spawning inner. Outer JoinHandle is dropped without await — tokio detaches, doesn't cancel. Inner runs to completion. ✓
  • wait_for_connection=true path (op_http_serve_on at line 1356): outer awaits join_handle.await?. Two ?'s collapsed into one — first unwraps JoinError, second propagates HttpNextError. Result type matches outer closure's Result<(), HttpNextError>. ✓
  • TLS path unchanged: serve_http2_autodetect is still called inline by serve_https at 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.

@nathanwhit
nathanwhit merged commit 030c822 into denoland:main May 6, 2026
136 checks passed
littledivy pushed a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…d#33887)

To avoid allocating the http2 future when it's only http1
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.

2 participants