Skip to content

Commit

Permalink
http: improve performance caused by primordials
Browse files Browse the repository at this point in the history
Refs: #29766

This works on destructuring primordials whithin libs/_http_agent

PR-URL: #30416
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
lrecknagel authored and BethGriggs committed Feb 6, 2020
1 parent b7bd84f commit 4f85f52
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@

'use strict';

const { Object } = primordials;
const {
Object: {
setPrototypeOf: ObjectSetPrototypeOf,
keys: ObjectKeys,
values: ObjectValues
}
} = primordials;

const net = require('net');
const EventEmitter = require('events');
Expand Down Expand Up @@ -124,8 +130,8 @@ function Agent(options) {
// Don't emit keylog events unless there is a listener for them.
this.on('newListener', maybeEnableKeylog);
}
Object.setPrototypeOf(Agent.prototype, EventEmitter.prototype);
Object.setPrototypeOf(Agent, EventEmitter);
ObjectSetPrototypeOf(Agent.prototype, EventEmitter.prototype);
ObjectSetPrototypeOf(Agent, EventEmitter);

function maybeEnableKeylog(eventName) {
if (eventName === 'keylog') {
Expand All @@ -136,7 +142,7 @@ function maybeEnableKeylog(eventName) {
agent.emit('keylog', keylog, this);
};
// Existing sockets will start listening on keylog now.
const sockets = Object.values(this.sockets);
const sockets = ObjectValues(this.sockets);
for (let i = 0; i < sockets.length; i++) {
sockets[i].on('keylog', this[kOnKeylog]);
}
Expand Down Expand Up @@ -371,7 +377,7 @@ Agent.prototype.destroy = function destroy() {
const sets = [this.freeSockets, this.sockets];
for (let s = 0; s < sets.length; s++) {
const set = sets[s];
const keys = Object.keys(set);
const keys = ObjectKeys(set);
for (let v = 0; v < keys.length; v++) {
const setName = set[keys[v]];
for (let n = 0; n < setName.length; n++) {
Expand Down

0 comments on commit 4f85f52

Please sign in to comment.