Skip to content

Commit 7b73e70

Browse files
mcollinaevanlucas
authored andcommitted
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: #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>
1 parent 03cb069 commit 7b73e70

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/timers.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ function TimersList(msecs, unrefed) {
207207
if (unrefed === true)
208208
timer.unref();
209209
timer.start(msecs);
210-
211-
timer[kOnTimeout] = listOnTimeout;
212210
}
213211

214-
function listOnTimeout() {
212+
// adds listOnTimeout to the C++ object prototype, as
213+
// V8 would not inline it otherwise.
214+
TimerWrap.prototype[kOnTimeout] = function listOnTimeout() {
215215
var list = this._list;
216216
var msecs = list.msecs;
217217

@@ -280,7 +280,7 @@ function listOnTimeout() {
280280
return;
281281

282282
this.close();
283-
}
283+
};
284284

285285

286286
// An optimization so that the try/finally only de-optimizes (since at least v8

0 commit comments

Comments
 (0)