Skip to content

perf(h1): reduce idle validation latency#22

Merged
ronag merged 1 commit into
masterfrom
codex/optimize-idle-socket-validation
Jul 11, 2026
Merged

perf(h1): reduce idle validation latency#22
ronag merged 1 commit into
masterfrom
codex/optimize-idle-socket-validation

Conversation

@ronag

@ronag ronag commented Jul 11, 2026

Copy link
Copy Markdown
Member

Summary

  • schedule reused-idle-socket validation with setImmediate instead of setTimeout(0)
  • cancel the matching handle with clearImmediate
  • retain the poll turn that surfaces unsolicited bytes / FIN / RST before the next request, without Node's timer floor

Adapted from nodejs/undici#5499 / issue #5493.

Performance

Five paired sequential keep-alive runs (1,000 measured requests/run):

  • baseline p50 median: 1.535 ms
  • patched p50 median: 0.123 ms
  • p50 latency reduction: 92.0%
  • median throughput: ~621 → ~5,668 req/s (+813%)

Validation

  • response-queue-poisoning + keep-alive/issue-810 suite: 14/14 pass
  • low-concurrency no-timeout full run under heavy host load: 512 unit pass, 6 skip; 162 node integration pass
  • npm run lint -- --quiet
  • git diff --check

@ronag
ronag marked this pull request as ready for review July 11, 2026 15:23
@ronag
ronag requested a review from Copilot July 11, 2026 15:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces HTTP/1 keep-alive reuse validation latency by scheduling the “idle socket validation” step with setImmediate instead of setTimeout(0), avoiding Node’s timer floor while still preserving the extra event-loop turn that can surface unsolicited bytes/FIN/RST before binding the next request.

Changes:

  • Switch reused-idle-socket validation scheduling from setTimeout(..., 0) to setImmediate(...).
  • Switch cancellation from clearTimeout(...) to clearImmediate(...).
  • Keep the existing .unref?.() behavior on the scheduled handle.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ronag
ronag merged commit b08b0d3 into master Jul 11, 2026
1 check passed
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