From 7b73e704caf891cb8a38370ace8367dc7798e2f7 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. PR-URL: https://github.com/nodejs/node/pull/18388 Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Anatoli Papirovski Reviewed-By: Colin Ihrig Reviewed-By: Jon Moss Reviewed-By: James M Snell Reviewed-By: Weijia Wang Reviewed-By: Ruben Bridgewater Reviewed-By: Jeremiah Senkpiel --- lib/timers.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/timers.js b/lib/timers.js index c2ce399234c..d637ca91ae4 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -207,11 +207,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; @@ -280,7 +280,7 @@ function listOnTimeout() { return; this.close(); -} +}; // An optimization so that the try/finally only de-optimizes (since at least v8