Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert https://github.com/nodejs/node/pull/20555 #20919

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions benchmark/timers/timers-cancel-unpooled.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,18 @@ const assert = require('assert');

const bench = common.createBenchmark(main, {
n: [1e6],
direction: ['start', 'end']
});

function main({ n, direction }) {
function main({ n }) {

const timersList = [];
for (var i = 0; i < n; i++) {
timersList.push(setTimeout(cb, i + 1));
}

var j;
bench.start();
if (direction === 'start') {
for (j = 0; j < n; j++) {
clearTimeout(timersList[j]);
}
} else {
for (j = n - 1; j >= 0; j--) {
clearTimeout(timersList[j]);
}
for (var j = 0; j < n + 1; j++) {
clearTimeout(timersList[j]);
}
bench.end(n);
}
Expand Down
16 changes: 4 additions & 12 deletions benchmark/timers/timers-insert-unpooled.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,18 @@ const assert = require('assert');

const bench = common.createBenchmark(main, {
n: [1e6],
direction: ['start', 'end']
});

function main({ direction, n }) {
function main({ n }) {
const timersList = [];

var i;
bench.start();
if (direction === 'start') {
for (i = 1; i <= n; i++) {
timersList.push(setTimeout(cb, i));
}
} else {
for (i = n; i > 0; i--) {
timersList.push(setTimeout(cb, i));
}
for (var i = 0; i < n; i++) {
timersList.push(setTimeout(cb, i + 1));
}
bench.end(n);

for (var j = 0; j < n; j++) {
for (var j = 0; j < n + 1; j++) {
clearTimeout(timersList[j]);
}
}
Expand Down
18 changes: 0 additions & 18 deletions benchmark/util/priority-queue.js

This file was deleted.

111 changes: 0 additions & 111 deletions lib/internal/priority_queue.js

This file was deleted.

22 changes: 14 additions & 8 deletions lib/internal/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ const {
// Timeout values > TIMEOUT_MAX are set to 1.
const TIMEOUT_MAX = 2 ** 31 - 1;

const kRefed = Symbol('refed');
const unrefedSymbol = Symbol('unrefed');

module.exports = {
TIMEOUT_MAX,
kTimeout: Symbol('timeout'), // For hiding Timeouts on other internals.
async_id_symbol,
trigger_async_id_symbol,
Timeout,
kRefed,
initAsyncResource,
setUnrefTimeout,
validateTimerDuration
Expand All @@ -51,7 +50,7 @@ function initAsyncResource(resource, type) {

// Timer constructor function.
// The entire prototype is defined in lib/timers.js
function Timeout(callback, after, args, isRepeat) {
function Timeout(callback, after, args, isRepeat, isUnrefed) {
after *= 1; // coalesce to number or NaN
if (!(after >= 1 && after <= TIMEOUT_MAX)) {
if (after > TIMEOUT_MAX) {
Expand All @@ -63,6 +62,7 @@ function Timeout(callback, after, args, isRepeat) {
after = 1; // schedule on next tick, follows browser behavior
}

this._called = false;
this._idleTimeout = after;
this._idlePrev = this;
this._idleNext = this;
Expand All @@ -75,16 +75,22 @@ function Timeout(callback, after, args, isRepeat) {
this._repeat = isRepeat ? after : null;
this._destroyed = false;

this[kRefed] = null;
this[unrefedSymbol] = isUnrefed;

initAsyncResource(this, 'Timeout');
}

Timeout.prototype.refresh = function() {
if (this[kRefed])
getTimers().active(this);
else
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 {
getTimers().active(this);
}

return this;
};
Expand Down Expand Up @@ -116,7 +122,7 @@ function setUnrefTimeout(callback, after, arg1, arg2, arg3) {
break;
}

const timer = new Timeout(callback, after, args, false);
const timer = new Timeout(callback, after, args, false, true);
getTimers()._unrefActive(timer);

return timer;
Expand Down
Loading