Repository navigation
Commit 24cb5f2
committed
http: keep request option copies in fast mode
The options of every client request are copied several times: once
in ClientRequest to merge the URL and the options, once more to
build the options handed to the agent, and again in Agent#addRequest
(on every request, including keep-alive reuse) and createSocket to
merge in the agent options. Each copy was a `{ __proto__: null, ...}`
literal or an Object.assign() onto `{ __proto__: null }`. V8 creates
such an object in dictionary mode, and copying from a dictionary-mode
source takes the generic slow path, so every copy in the chain was
slow and fed a slow source into the next one.
Build each copy as an ordinary object literal and set its prototype
to null afterwards, which leaves a fast-mode object with a null
prototype and the same own properties in the same order. The same is
done for the copy of the options in the http and https Agent
constructors, which is the source of the agent options merged into
every request.
On a keep-alive client against a raw TCP responder (10 runs each,
medians, busy machine) this goes from 68.7k to 83.1k requests per
second and from 8.7 to 6.4 us of user CPU per request.
Assisted-by: claude:opus-5.5
Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>1 parent 2aef805 commit 24cb5f2
3 files changed
Lines changed: 7 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
489 | 489 | | |
490 | 490 | | |
491 | 491 | | |
492 | | - | |
| 492 | + | |
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
378 | | - | |
| 378 | + | |
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| |||
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
448 | | - | |
| 448 | + | |
449 | 449 | | |
450 | 450 | | |
451 | 451 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
| |||
363 | 362 | | |
364 | 363 | | |
365 | 364 | | |
366 | | - | |
| 365 | + | |
| 366 | + | |
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
414 | | - | |
| 414 | + | |
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
| |||
0 commit comments