Commit 086741d
timers: reuse Timeout objects in setStreamTimeout
Rearm the stream's existing Timeout object instead of allocating a new
Timeout and a bound callback on every setTimeout() call. The HTTP
server disarms and rearms the keep-alive timeout twice per request, so
this saves two allocations and the associated async resource churn on
every request over a keep-alive connection.
The async resource is re-initialized on reuse, so async_hooks observes
the same init/destroy sequence as before.
A microbenchmark of the setTimeout(msecs)/setTimeout(0) cycle improves
by 2.2x (205.9ns to 92.8ns), and benchmark/http/simple.js
(type=buffer len=1024 chunks=1 chunkedEnc=0 c=50) improves by 3.70%
(t=2.15, 40 samples per binary with server and load generator pinned
to disjoint CPU sets).
Assisted-by: Claude Fable 5 (Claude Code)
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: #64254
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>1 parent efbbb9a commit 086741d
2 files changed
Lines changed: 40 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
236 | 240 | | |
237 | 241 | | |
238 | 242 | | |
| |||
244 | 248 | | |
245 | 249 | | |
246 | 250 | | |
| 251 | + | |
| 252 | + | |
247 | 253 | | |
248 | 254 | | |
249 | 255 | | |
| |||
252 | 258 | | |
253 | 259 | | |
254 | 260 | | |
255 | | - | |
| 261 | + | |
| 262 | + | |
256 | 263 | | |
257 | 264 | | |
258 | 265 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
420 | 450 | | |
421 | 451 | | |
422 | 452 | | |
| |||
704 | 734 | | |
705 | 735 | | |
706 | 736 | | |
| 737 | + | |
707 | 738 | | |
708 | 739 | | |
709 | 740 | | |
| |||
0 commit comments