setTimeout: do not calculate Timeout._when property
Dramatically improves Timer performance.
This commit is contained in:
parent
929e4d9c9a
commit
39058bef07
@ -263,12 +263,15 @@ var Timeout = function(after) {
|
|||||||
this._idleTimeout = after;
|
this._idleTimeout = after;
|
||||||
this._idlePrev = this;
|
this._idlePrev = this;
|
||||||
this._idleNext = this;
|
this._idleNext = this;
|
||||||
this._when = Date.now() + after;
|
this._idleStart = null;
|
||||||
|
this._onTimeout = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
Timeout.prototype.unref = function() {
|
Timeout.prototype.unref = function() {
|
||||||
if (!this._handle) {
|
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;
|
if (delay < 0) delay = 0;
|
||||||
exports.unenroll(this);
|
exports.unenroll(this);
|
||||||
this._handle = new Timer();
|
this._handle = new Timer();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user