diff options
author | Anatoli Papirovski <apapirovski@mac.com> | 2018-01-31 10:34:31 -0500 |
---|---|---|
committer | Anatoli Papirovski <apapirovski@mac.com> | 2018-02-04 11:04:12 -0500 |
commit | a986158cbf931da9d62eed0c921c105e29b76eda (patch) | |
tree | ed37a135dfe451659e6d838224cde9bc134ad5ae /lib/timers.js | |
parent | 9b8e1c2e4f0a4254b295316b10136a28cc36db4c (diff) | |
download | android-node-v8-a986158cbf931da9d62eed0c921c105e29b76eda.tar.gz android-node-v8-a986158cbf931da9d62eed0c921c105e29b76eda.tar.bz2 android-node-v8-a986158cbf931da9d62eed0c921c105e29b76eda.zip |
timers: re-enter C++ less frequently
Pass in Timer.now() as an argument of kOnTimeout instead of always
re-entering C++ to get it. Also don't constantly call Timer.now()
from ontimeout, even when it isn't needed. Improves performance
on our pooled benchmark by upwards of 40%.
PR-URL: https://github.com/nodejs/node/pull/18486
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'lib/timers.js')
-rw-r--r-- | lib/timers.js | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/timers.js b/lib/timers.js index a91de76d7f..83affee7d8 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -223,13 +223,11 @@ function TimersList(msecs, unrefed) { // adds listOnTimeout to the C++ object prototype, as // V8 would not inline it otherwise. -TimerWrap.prototype[kOnTimeout] = function listOnTimeout() { +TimerWrap.prototype[kOnTimeout] = function listOnTimeout(now) { var list = this._list; var msecs = list.msecs; debug('timeout callback %d', msecs); - - var now = TimerWrap.now(); debug('now: %d', now); var diff, timer; @@ -430,11 +428,12 @@ setTimeout[internalUtil.promisify.custom] = function(after, value) { exports.setTimeout = setTimeout; -function ontimeout(timer) { +function ontimeout(timer, start) { var args = timer._timerArgs; if (typeof timer._onTimeout !== 'function') return promiseResolve(timer._onTimeout, args[0]); - const start = TimerWrap.now(); + if (start === undefined && timer._repeat) + start = TimerWrap.now(); if (!args) timer._onTimeout(); else @@ -518,11 +517,11 @@ exports.clearInterval = function(timer) { }; -function unrefdHandle() { +function unrefdHandle(now) { try { // Don't attempt to call the callback if it is not a function. if (typeof this.owner._onTimeout === 'function') { - ontimeout(this.owner); + ontimeout(this.owner, now); } } finally { // Make sure we clean up if the callback is no longer a function |