Google Chrome 52.0.2713.0 (Official Build) canary (64-bit)
Revision 939788c10e98a18cb74d5311f8792105930d9bd9-refs/heads/master@{#388380}
OS Mac OS X
Blink 537.36 (@939788c10e98a18cb74d5311f8792105930d9bd9)
1) Load this page:
<button onclick="schedule()">Click me</button>
<script>
function schedule() {
for (var i = 0; i < 1000; i++) {
clearTimeout(setTimeout(function() { }, 0));
}
var t = performance.now();
setTimeout(function() {
document.body.appendChild(document.createElement("div")).textContent = performance.now() - t;
}, 0);
}
</script>
2) Start about:tracing
3) Click the button.
4) Note the printed time.
5) You can click the button again to get another number.
You'll see there's 1000 tasks that fire right after the script runs but don't do anything, those are all the cancelled tasks. Then the task that's printing the time gets run after that.
Firefox and Safari print ~1 in this case, Chrome prints 8 on my Macbook Pro. Note that tracing also seems to make this stuff **much** slower, it takes 19ms instead of 8ms when tracing is active. So the per task overhead of tracing is apparently quite large.
Note that this impacts all the builtin timers inside Blink as well, any time we call cancel() it's actually leaving around tasks which wastes time and battery being awake.
ex. issue 605701 is a case of this.
I think we need to figure out how to not wake up and burn CPU for all cancelled tasks.
|
Deleted:
timer-clearing.html
372 bytes
|
Comment 1 by esprehn@chromium.org
, Apr 21 2016555 KB
555 KB Download