Permalink
Browse files

process: improve performance of nextTick

This replaces TickObject with an object literal. This offers
performance improvements of up to ~20%.

PR-URL: #8932
Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information...
evanlucas authored and jasnell committed Oct 4, 2016
1 parent cde2ca9 commit aedb72e03b43ed863406cc34302edb5caa7e5150
Showing with 5 additions and 7 deletions.
  1. +5 −7 lib/internal/process/next_tick.js
@@ -131,12 +131,6 @@ function setupNextTick() {
} while (tickInfo[kLength] !== 0);
}

function TickObject(c, args) {
this.callback = c;
this.domain = process.domain || null;
this.args = args;
}

function nextTick(callback) {
if (typeof callback !== 'function')
throw new TypeError('callback is not a function');
@@ -151,7 +145,11 @@ function setupNextTick() {
args[i - 1] = arguments[i];
}

nextTickQueue.push(new TickObject(callback, args));
nextTickQueue.push({
callback,
domain: process.domain || null,
args
});
tickInfo[kLength]++;
}
}

0 comments on commit aedb72e

Please sign in to comment.