Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.3k
Closed
Labels
confirmed-bugIssues with confirmed bugs.Issues with confirmed bugs.timersIssues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
Description
Affected Versions: 0.11+
The issue came up during testing of node-toobusy. I found that in newer Node versions, there seemed to be an artificial delay introduced between setTimeout() calls if there is a significant amount of synchronous work in them. The delay seems to always equal the amount of work done, as if Node is measuring the time taken by the function and delaying it by that amount of time to keep the loop free.
Reproduction script:
functiontightWork(duration){varstart=Date.now();while((Date.now()-start)<duration){for(vari=0;i<1e5;)i++;}}varcount=0;varlast=Date.now();functionload(){if(count++>10)return;// This measures the amount of time between setTimeout() being called,// and it actually firing.console.log('tick delta:',(Date.now()-last));tightWork(100);last=Date.now();setTimeout(load,0);}load();Output (similar on 0.11.x and above):
$ node -v v5.6.0 $ node index tick delta: 13 tick delta: 1 tick delta: 105 tick delta: 104 tick delta: 105 tick delta: 105 tick delta: 105 tick delta: 104 tick delta: 105 tick delta: 105 tick delta: 105Yet this doesn't happen on 0.10:
$ node -v v0.10.41 $ node index tick delta: 8 tick delta: 2 tick delta: 1 tick delta: 1 tick delta: 1 tick delta: 1 tick delta: 1 tick delta: 1 tick delta: 1 tick delta: 1 tick delta: 1Metadata
Metadata
Assignees
Labels
confirmed-bugIssues with confirmed bugs.Issues with confirmed bugs.timersIssues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.