timers: attach listOnTimeout function to TimerWrap

Make the listOnTimeout function inline by attaching it to the TimeWrap
prototype.
It improves insertion and cancellation time of unpooled timers by 18%
and 28% respectively.

PR-URL: https://github.com/nodejs/node/pull/18388
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
Matteo Collina 2018-01-25 21:51:56 +08:00
parent 5c8ce90c2f
commit eb34278dcc

View File

@ -218,11 +218,11 @@ function TimersList(msecs, unrefed) {
if (unrefed === true)
timer.unref();
timer.start(msecs);
timer[kOnTimeout] = listOnTimeout;
}
function listOnTimeout() {
// adds listOnTimeout to the C++ object prototype, as
// V8 would not inline it otherwise.
TimerWrap.prototype[kOnTimeout] = function listOnTimeout() {
var list = this._list;
var msecs = list.msecs;
@ -291,7 +291,7 @@ function listOnTimeout() {
return;
this.close();
}
};
// An optimization so that the try/finally only de-optimizes (since at least v8