diff options
author | Anatoli Papirovski <apapirovski@mac.com> | 2018-05-05 19:50:21 +0200 |
---|---|---|
committer | Anatoli Papirovski <apapirovski@mac.com> | 2018-05-22 23:26:12 +0400 |
commit | 23a56e0c28cd828ef0cabb05b30e03cc8cb57dd5 (patch) | |
tree | c389f61071481a949bcea2d78bffb687ec138221 /lib/internal/timers.js | |
parent | 6f6f7f749bd6847278836832542116f371ab3aa6 (diff) | |
download | android-node-v8-23a56e0c28cd828ef0cabb05b30e03cc8cb57dd5.tar.gz android-node-v8-23a56e0c28cd828ef0cabb05b30e03cc8cb57dd5.tar.bz2 android-node-v8-23a56e0c28cd828ef0cabb05b30e03cc8cb57dd5.zip |
timers: use only a single TimerWrap instance
Hang all timer lists off a single TimerWrap and use the PriorityQueue
to manage expiration priorities. This makes the Timers code clearer,
consumes significantly less resources and improves performance.
PR-URL: https://github.com/nodejs/node/pull/20555
Fixes: https://github.com/nodejs/node/issues/16105
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/internal/timers.js')
-rw-r--r-- | lib/internal/timers.js | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/lib/internal/timers.js b/lib/internal/timers.js index 801fce1cc3..44ebc65dc1 100644 --- a/lib/internal/timers.js +++ b/lib/internal/timers.js @@ -19,7 +19,7 @@ const { // Timeout values > TIMEOUT_MAX are set to 1. const TIMEOUT_MAX = 2 ** 31 - 1; -const unrefedSymbol = Symbol('unrefed'); +const kRefed = Symbol('refed'); module.exports = { TIMEOUT_MAX, @@ -27,6 +27,7 @@ module.exports = { async_id_symbol, trigger_async_id_symbol, Timeout, + kRefed, initAsyncResource, setUnrefTimeout, validateTimerDuration @@ -50,7 +51,7 @@ function initAsyncResource(resource, type) { // Timer constructor function. // The entire prototype is defined in lib/timers.js -function Timeout(callback, after, args, isRepeat, isUnrefed) { +function Timeout(callback, after, args, isRepeat) { after *= 1; // coalesce to number or NaN if (!(after >= 1 && after <= TIMEOUT_MAX)) { if (after > TIMEOUT_MAX) { @@ -62,7 +63,6 @@ function Timeout(callback, after, args, isRepeat, isUnrefed) { after = 1; // schedule on next tick, follows browser behavior } - this._called = false; this._idleTimeout = after; this._idlePrev = this; this._idleNext = this; @@ -75,22 +75,16 @@ function Timeout(callback, after, args, isRepeat, isUnrefed) { this._repeat = isRepeat ? after : null; this._destroyed = false; - this[unrefedSymbol] = isUnrefed; + this[kRefed] = null; initAsyncResource(this, 'Timeout'); } Timeout.prototype.refresh = function() { - if (this._handle) { - // Would be more ideal with uv_timer_again(), however that API does not - // cause libuv's sorted timers data structure (a binary heap at the time - // of writing) to re-sort itself. This causes ordering inconsistencies. - this._handle.start(this._idleTimeout); - } else if (this[unrefedSymbol]) { - getTimers()._unrefActive(this); - } else { + if (this[kRefed]) getTimers().active(this); - } + else + getTimers()._unrefActive(this); return this; }; @@ -122,7 +116,7 @@ function setUnrefTimeout(callback, after, arg1, arg2, arg3) { break; } - const timer = new Timeout(callback, after, args, false, true); + const timer = new Timeout(callback, after, args, false); getTimers()._unrefActive(timer); return timer; |