Skip to content

perf(h1): drop idle-socket timer floor with a ref'd setImmediate - #5707

Merged
anonrig merged 1 commit into
mainfrom
cursor/idle-socket-immediate-50f6
Aug 21, 2026
Merged

perf(h1): drop idle-socket timer floor with a ref'd setImmediate#5707
anonrig merged 1 commit into
mainfrom
cursor/idle-socket-immediate-50f6

Conversation

@anonrig

@anonrig anonrig commented Aug 21, 2026

Copy link
Copy Markdown
Member

This relates to...

Rationale

Sequential fetch() / HTTP/1.1 keep-alive reuse was paying Node's setTimeout(0) timer floor (~1.3–1.5ms) on every request. That dominates loopback / low-RTT workloads.

#5499 switched this to setImmediate and was reverted in #5606 because an unref'd Immediate lets poll block for ~500ms when the event loop is otherwise idle.

Changes

Features

N/A

Bug Fixes

N/A

Breaking Changes and Deprecations

N/A

Benchmarks

Re-run 2026-08-21 on Node v22.14.0 (linux x64, Intel Xeon, 4 cores). Medians of 5 runs vs main @ 181c293.

Sequential keep-alive fetch().text() on loopback (connections: 1, pipelining: 1, 2000 iterations after 300 warmup):

p50 p90 p99
main (setTimeout(0)) 1.47 ms 1.63 ms 1.84 ms
this PR (setImmediate) 0.20 ms 0.29 ms 0.48 ms

~7.5× faster at p50.

Status

Defer idle keep-alive validation to a ref'd setImmediate so it still
runs after poll (GHSA-35p6-xmwp-9g52) without Node's setTimeout(0)
timer floor or the unref'd-Immediate poll stall from #5606.

Assisted by Cursor
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
@anonrig
anonrig requested a review from mcollina August 21, 2026 01:50
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.48%. Comparing base (181c293) to head (b5d45df).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5707   +/-   ##
=======================================
  Coverage   93.47%   93.48%           
=======================================
  Files         110      110           
  Lines       38892    38900    +8     
=======================================
+ Hits        36354    36365   +11     
+ Misses       2538     2535    -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@mcollina
mcollina requested review from ronag and tsctx August 21, 2026 02:38
@anonrig
anonrig merged commit 8c9182e into main Aug 21, 2026
38 checks passed
@anonrig
anonrig deleted the cursor/idle-socket-immediate-50f6 branch August 21, 2026 03:54
@mcollina

Copy link
Copy Markdown
Member

Historical note: #5609 proposed the same central fix as this PR.

Strictly speaking, #5609 was not formally rejected: it received no reviews and was voluntarily closed as apparently obsolete. Its branch was also rebased after #5606, so its final displayed diff no longer clearly represents the original ref'd-Immediate proposal. Nevertheless, #5609 is the closest prior proposal and belongs in the history of this change.

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.

4 participants