diff options
author | wicked <wicked@alawar.com> | 2012-10-25 11:53:35 +0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-03-28 10:40:15 -0700 |
commit | 39058bef0733e6fae3cf160d71935127eab97bdd (patch) | |
tree | a432ba36081f4991ce5f300bbec598df22c1a364 | |
parent | 929e4d9c9a09947c2ec86ee14f6d312b1bda1a16 (diff) | |
download | node-39058bef0733e6fae3cf160d71935127eab97bdd.tar.gz |
setTimeout: do not calculate Timeout._when property
Dramatically improves Timer performance.
-rw-r--r-- | lib/timers.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/timers.js b/lib/timers.js index 3900d61c9..8431b2ddd 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -263,12 +263,15 @@ var Timeout = function(after) { this._idleTimeout = after; this._idlePrev = this; this._idleNext = this; - this._when = Date.now() + after; + this._idleStart = null; + this._onTimeout = null; }; Timeout.prototype.unref = function() { if (!this._handle) { - var delay = this._when - Date.now(); + var now = Date.now(); + if (!this._idleStart) this._idleStart = now; + var delay = this._idleStart + this._idleTimeout - now; if (delay < 0) delay = 0; exports.unenroll(this); this._handle = new Timer(); |