Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

5-50% speed up setTimeout() #4193

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/timers.js
Expand Up @@ -248,12 +248,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();
Expand Down