mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
async_hooks: update defaultTriggerAsyncIdScope for perf
The existing version of defaultTriggerAsyncIdScope creates an Array for the callback's arguments which is highly inefficient. Instead, use rest syntax and allow V8 to do that work for us. This yields roughly 2x performance for this particular function. PR-URL: https://github.com/nodejs/node/pull/18004 Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
5a1aeab2db
commit
fbad8bb1fa
@ -452,8 +452,8 @@ Socket.prototype.send = function(buffer,
|
||||
const afterDns = (ex, ip) => {
|
||||
defaultTriggerAsyncIdScope(
|
||||
this[async_id_symbol],
|
||||
[ex, this, ip, list, address, port, callback],
|
||||
doSend
|
||||
doSend,
|
||||
ex, this, ip, list, address, port, callback
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -260,7 +260,7 @@ function getDefaultTriggerAsyncId() {
|
||||
}
|
||||
|
||||
|
||||
function defaultTriggerAsyncIdScope(triggerAsyncId, opaque, block) {
|
||||
function defaultTriggerAsyncIdScope(triggerAsyncId, block, ...args) {
|
||||
// CHECK(Number.isSafeInteger(triggerAsyncId))
|
||||
// CHECK(triggerAsyncId > 0)
|
||||
const oldDefaultTriggerAsyncId = async_id_fields[kDefaultTriggerAsyncId];
|
||||
@ -268,7 +268,7 @@ function defaultTriggerAsyncIdScope(triggerAsyncId, opaque, block) {
|
||||
|
||||
var ret;
|
||||
try {
|
||||
ret = Reflect.apply(block, null, opaque);
|
||||
ret = Reflect.apply(block, null, args);
|
||||
} finally {
|
||||
async_id_fields[kDefaultTriggerAsyncId] = oldDefaultTriggerAsyncId;
|
||||
}
|
||||
|
14
lib/net.js
14
lib/net.js
@ -317,7 +317,7 @@ function onSocketFinish() {
|
||||
return this.destroy();
|
||||
|
||||
var err = defaultTriggerAsyncIdScope(
|
||||
this[async_id_symbol], [this, afterShutdown], shutdownSocket
|
||||
this[async_id_symbol], shutdownSocket, this, afterShutdown
|
||||
);
|
||||
|
||||
if (err)
|
||||
@ -1043,7 +1043,7 @@ Socket.prototype.connect = function(...args) {
|
||||
path);
|
||||
}
|
||||
defaultTriggerAsyncIdScope(
|
||||
this[async_id_symbol], [this, path], internalConnect
|
||||
this[async_id_symbol], internalConnect, this, path
|
||||
);
|
||||
} else {
|
||||
lookupAndConnect(this, options);
|
||||
@ -1089,8 +1089,8 @@ function lookupAndConnect(self, options) {
|
||||
if (self.connecting)
|
||||
defaultTriggerAsyncIdScope(
|
||||
self[async_id_symbol],
|
||||
[self, host, port, addressType, localAddress, localPort],
|
||||
internalConnect
|
||||
internalConnect,
|
||||
self, host, port, addressType, localAddress, localPort
|
||||
);
|
||||
});
|
||||
return;
|
||||
@ -1118,7 +1118,7 @@ function lookupAndConnect(self, options) {
|
||||
debug('connect: dns options', dnsopts);
|
||||
self._host = host;
|
||||
var lookup = options.lookup || dns.lookup;
|
||||
defaultTriggerAsyncIdScope(self[async_id_symbol], [], function() {
|
||||
defaultTriggerAsyncIdScope(self[async_id_symbol], function() {
|
||||
lookup(host, dnsopts, function emitLookup(err, ip, addressType) {
|
||||
self.emit('lookup', err, ip, addressType, host);
|
||||
|
||||
@ -1140,8 +1140,8 @@ function lookupAndConnect(self, options) {
|
||||
self._unrefTimer();
|
||||
defaultTriggerAsyncIdScope(
|
||||
self[async_id_symbol],
|
||||
[self, ip, port, addressType, localAddress, localPort],
|
||||
internalConnect
|
||||
internalConnect,
|
||||
self, ip, port, addressType, localAddress, localPort
|
||||
);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user