From 2c0fcbcd8c9f8c08fd1907b588259b13fb2e446a Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Thu, 25 Jan 2018 21:51:56 +0800 Subject: [PATCH] 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. --- lib/timers.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/timers.js b/lib/timers.js index 6fc552fac7d444..cc8d6432058a82 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -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