Repository navigation
Conversation
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>
Collaborator
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67395 +/- ##
==========================================
- Coverage 90.74% 90.73% -0.01%
==========================================
Files 798 798
Lines 280083 280083
Branches 53900 53888 -12
==========================================
- Hits 254166 254139 -27
- Misses 16217 16258 +41
+ Partials 9700 9686 -14
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the
{ __proto__: null, ...options }copies on the client request path and thehttp/httpsAgentconstructors withObjectSetPrototypeOf({ ...options }, 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