Skip to content

Commit

Permalink
timers: make previous change simpler
Browse files Browse the repository at this point in the history
Instead of adding a property on the list of timers, simply compare the
current value of what represents the current time if its value is
earlier than the time of the current timer being processed.
  • Loading branch information
Julien Gilli committed Apr 30, 2015
1 parent 8b00d74 commit 52c35bd
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ function listOnTimeout() {
debug('timeout callback ' + msecs);

var now = Timer.now();
// now's value has been updated, consider that it doesn't need to be updated
// unless a timer is added within the loop that processes the timers list
// below
list._addedTimer = false;
debug('now: %d', now);

var first;
Expand All @@ -95,10 +91,9 @@ function listOnTimeout() {
// update the value of "now" so that timing computations are
// done correctly. See test/simple/test-timers-blocking-callback.js
// for more information.
if (list._addedTimer) {
if (now < first._monotonicStartTime) {

This comment has been minimized.

Copy link
@indutny

indutny Apr 30, 2015

This condition is going to be called almost always, while the previous only rarely.

This comment has been minimized.

Copy link
@misterdjules

misterdjules Apr 30, 2015

Owner

@indutny My understanding is that now < first._monotonicStartTime should evaluate to true only if first was added while processing the list of timers. So I would think the two conditions are equivalent in terms of behavior, or am I missing something?

Do you have an example where the second approach would lead to Timer.now() being called more often?

Thank you!

now = Timer.now();
debug('now: %d', now);
list._addedTimer = false;
}

var diff = now - first._monotonicStartTime;
Expand Down Expand Up @@ -198,12 +193,6 @@ exports.active = function(item) {
}

list = lists[msecs];
// Set _addedTimer so that listOnTimeout can refresh
// its current time value to avoid wrong timing computation
// in case timers callback block for a while.
// See test/simple/test-timers-blocking-callback.js for more
// details
list._addedTimer = true;
}
};

Expand Down

0 comments on commit 52c35bd

Please sign in to comment.