whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.1k stars 2.67k forks source link

Event loop: update the rendering step mismatches implementations in subtle ways #9824

Open noamr opened 1 year ago

noamr commented 1 year ago

What is the issue with the HTML Standard?

There are a few places in the event loop processing model, specifically in its relationship with updating the rendering, that differs from how it's implemented in the difference browser. This is web observable in subtle ways:

annevk commented 1 year ago

I think we should make "update the rendering" its own task with its own task source. The implicit task source prioritization algorithm would then attempt to make that task hit the desired frame rate.

The issue with UI events has been known for a long time. https://github.com/w3c/uievents/issues/238#issuecomment-510106422 describes (rather briefly) what needs to be done: we need to turn the OS inputs into abstract algorithms from which we integrate with the event loop, create the relevant event objects, initialize their fields correctly, handle dispatch and cancelation, etc.

cc @rniwa @smaug----

Kaiido commented 1 year ago

The frequency rate of events while the pointing device is moved is implementation-, device-, and platform-specific, but multiple consecutive mousemove events SHOULD be fired for sustained pointer-device movement, rather than a single event for each instance of mouse movement. Implementations are encouraged to determine the optimal frequency rate to balance responsiveness with performance.

But then again, there is the pointerawupdate event that should not be throttled the same way. Probably having clearer hooks, or even more inclusion of UI events into HTML would help here.

noamr commented 1 year ago

The way I would spec it in a way that's closer to implementations is that there are "in parallel" step that continuously wait for a rendering opportunity, save the timestamp when that rendering opportunity was available, and then the main event loop would read that timestamp (or some such). VSync or not etc. would be more implementation defined.

  • For the second point, I remember I read that Firefox also uses a task for update the rendering, but I didn't know it's observable. Could you share an example test? That's indeed gonna be more and more important with stuff like prioritized task scheduling.

Yes, this is observable in longtasks: https://wpt.fyi/results/longtask-timing/longtask-in-raf.html?label=experimental&label=master&aligned

  • For the last point, indeed UI events are ill-defined. It seems that you are referring to the fact mouse events are throttled to the monitor's frame rate though, which is in accordance to what UI events ask for, e.g. for mousemove:

The frequency rate of events while the pointing device is moved is implementation-, device-, and platform-specific, but multiple consecutive mousemove events SHOULD be fired for sustained pointer-device movement, rather than a single event for each instance of mouse movement. Implementations are encouraged to determine the optimal frequency rate to balance responsiveness with performance.

But then again, there is the pointerawupdate event that should not be throttled the same way. Probably having clearer hooks, or even more inclusion of UI events into HTML would help here.

Yes, I think several events are frame-throttled, and potentially differently at different browsers, and this is observable and unspecced (except for mousemove perhaps).

smaug---- commented 1 year ago

FWIW, scroll/resize aren't UI events. User input event handling scheduling is very much undefined currently. And things like pointerrawupdate make it even more complicated. I believe in normal cases both Gecko and Blink try to handle non-pointerrawupdate (which might be still implemented in blink only) user input right before update rendering step. Some interesting scheduling issues rise when update rendering steps take too much time, or if there are tasks which take lots of time and lead to rending updates to be delayed.

https://github.com/WICG/scheduling-apis/issues/67 has some information about the current behavior.

noamr commented 10 months ago

Finally got around to this, see #10007