Repository navigation
Commit 98f32da
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.
Put the spread first and `__proto__: null` last in each literal. V8
then clones the source straight into an object with a null
prototype, which leaves a fast-mode object with 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.
benchmark/http/create-clientrequest.js improves by 5 to 24 % at the
default e=1 (100 runs) and by 47 to 82 % with e=6 (60 runs).
Assisted-by: claude:opus-5.5
Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>1 parent 55da353 commit 98f32da
3 files changed
Lines changed: 7 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
497 | | - | |
| 497 | + | |
498 | 498 | | |
499 | 499 | | |
500 | 500 | | |
| |||
| 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 | | |
| |||
365 | 364 | | |
366 | 365 | | |
367 | 366 | | |
368 | | - | |
| 367 | + | |
| 368 | + | |
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
416 | | - | |
| 416 | + | |
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
| |||
0 commit comments