animation-frame
animation-frame copied to clipboard
Latency due to setTimeout in Scheduler
I'm using Firefox 56.0.1 (64-bit) and Chrome 62.0.3202.62 (64-bit) on Windows 10.
In pure JavaScript, when I call setTimeout(changeStuff, 0)
inside my requestAnimationFrame
callback, changeStuff
will often not be run until after the rendering deadline, causing the changes it makes to show up noticeably later than everything else that the requestAnimationFrame
callback does.
The AnimationFrame package suffers from this exact problem. The call to setTimeout
occurs here, and it causes Elm to frequently miss the rendering deadline.
I created a test program using a modified version of the AnimationFrame
module to explore the issue further. The requestAnimationFrame
callback is modified to change the style of an element at regular intervals. The Elm update
function, triggered by the exact same callback, changes the style of its own element in the same way. The repository is here.
I used a screen capture program and scrubbed through the video to see how often Elm showed noticeable latency relative to pure JavaScript. In Firefox, there was latency in 19 out of 20 frames, whereas in Chrome there was latency in 8 out of 20 frames.
I don't know whether this issue is worth fixing, or whether it's even possible to fix. My main goal in creating this issue is to save other people the headache of trying to diagnose the problem.