From 3b169f1dbd6b0e36adef1470ea21db3f5f5e417d Mon Sep 17 00:00:00 2001 From: Lucas Recknagel Date: Tue, 12 Nov 2019 15:30:48 +0000 Subject: [PATCH] http: improve performance caused by primordials MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs: https://github.com/nodejs/node/issues/29766 This works on destructuring primordials whithin libs/_http_agent PR-URL: https://github.com/nodejs/node/pull/30416 Reviewed-By: Colin Ihrig Reviewed-By: Matteo Collina Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso Reviewed-By: Trivikram Kamat Reviewed-By: Ruben Bridgewater Reviewed-By: Gireesh Punathil --- lib/_http_agent.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/_http_agent.js b/lib/_http_agent.js index f8aa395aefdb38..270569eab9ffd8 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -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'); @@ -129,8 +135,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') { @@ -141,7 +147,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]); } @@ -381,7 +387,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++) {