From f24f352213e17e63b7a797d65b5c50d0aa21cbfd 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 2f146f3b9f1171..0f1bcb00b1c304 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'); @@ -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') { @@ -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]); } @@ -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++) {