Repository navigation
Conversation
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67395 +/- ##
=======================================
Coverage 90.66% 90.67%
=======================================
Files 799 799
Lines 280245 280243 -2
Branches 54121 54121
=======================================
+ Hits 254097 254098 +1
- Misses 16277 16278 +1
+ Partials 9871 9867 -4
🚀 New features to boost your workflow:
|
pimterry
left a comment
There was a problem hiding this comment.
This is neat, it's a good spot of a case we can speed up a bit.
That said, I pointed the new Fable at it to test this and explore a bit, and I think there's an even faster option 😄: { ...options, __proto__: null } (i.e. switching the order so we spread first, and __proto__ comes last).
This creates the object with the fast path clone for spread (here) but directly sets the prototype up front, so it skips the subsequent method call and prototype change of ObjectSetPrototypeOf(...), and still ends up in fast mode.
Do you want to take a look? Or if not I agree this is good regardless, we could merge now and test further improvements later.
|
Wow, that looks great, yeah let's do that instead. I'll test and push the change |
| EventEmitter.call(this); | ||
|
|
||
| this.options = { __proto__: null, ...options }; | ||
| this.options = ObjectSetPrototypeOf({ ...options }, null); |
There was a problem hiding this comment.
The ObjectSetPrototypeOf call also has overhead. We can achieve the same fast-properties result with something like...
const kNullProtoObject = { __proto__: null };
this.options = { __proto__: kNullProtoObject, ...options };Should come out a bit faster.
There was a problem hiding this comment.
hey James, thanks for the review
what do you think about this?
it's 3-4% slower than your suggestion, but it still doesn't use ObjectSetPrototypeOf while keeping fast properties and the same behavior in all cases- i'm kind of surprised it works to be honest 😂
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>
24cb5f2 to
98f32da
Compare
| EventEmitter.call(this); | ||
|
|
||
| this.options = { __proto__: null, ...options }; | ||
| this.options = { ...options, __proto__: null }; |
There was a problem hiding this comment.
The { __proto__: kNullProtoObject, ...options } approach is better, I believe.
Replaces the
{ __proto__: null, ...options }copies on the client request path and thehttp/httpsAgentconstructors with{ ...options, __proto__: null }so they stay out of dictionary modebenchmark/http/create-clientrequest.js(50 runs at the defaulte=1, 30 runs with--set e=6):e=1e=6Server benchmarks driven by
benchmarker=test-double-http(s), where theclient half is
http.request(30 runs,c=50 chunks=1 len=4 type=buffer):http/simple.jshttps/simple.js