Created
July 12, 2016 19:34
-
-
Save runspired/9aa4c107df8a021d2fe7fe8cdb2bb456 to your computer and use it in GitHub Desktop.
requestIdleCallback timing guarantees
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lastFlushed = undefined; | |
function floodScheduler(n) { | |
for (var i = 0; i < 10; i++) { | |
for (var j = 0; j < n; j++) { | |
var fn = function logPos(i, j) { | |
var thisFlush = (i * n) + j; | |
if (lastFlushed || lastFlushed === 0) { | |
if (lastFlushed + 1 !== thisFlush) { | |
console.error('Order MisMatch', lastFlushed, thisFlush, i, j); | |
} | |
} | |
lastFlushed = thisFlush; | |
}.bind(null, i, j) | |
setTimeout(fn, i); | |
} | |
} | |
var now = performance.now(); | |
for (var id = 0; id < 10; id++) { | |
var fn = function logIdlePos(start, i) { | |
var elapsed = performance.now() - start; | |
// we allow a little jiggle | |
if (elapsed > i + 5) { | |
console.error('Idle Callback Delayed Too Long', start, elapsed, i); | |
} | |
lastFlushed = 'idle-' + i; | |
}.bind(undefined, now, id); | |
requestIdleCallback(fn, { timeout: id }); | |
} | |
} | |
floodScheduler(10000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Showing that with
raf
we can still get 60FPS despite pushing 15.5ms of work within it.