Closed Bug 1527181 Opened 5 years ago Closed 3 years ago

Add flush/resolve microtask heuristic

Categories

(Core :: Graphics: CanvasWebGL, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
93 Branch
Tracking Status
firefox93 --- fixed

People

(Reporter: jgilbert, Assigned: jgilbert)

Details

(Whiteboard: gfx-noted)

Attachments

(1 file)

Severity: normal → enhancement

<jgilbert> Jeff Gilbert (jdashg) heycam: Hi! Is there a way to enqueue a Runnable (micro-task??) to run after the current JS Task?
<heycam> jgilbert: I'm sure there is but I'm not really familiar with microtask stuff
<jgilbert> Jeff Gilbert (jdashg) heycam: can you route me if someone else would know more?
<heycam> (there's a type called MicroTaskRunnable I see)
jgilbert: git log tells me mrbkap and asuth
they've written / reviewed a microtask related patch
or smaug probably
<smaug> yes, use MicroTaskRunnable. (and what is a JS Task?)
(I guess it is just a task :) )
<jgilbert> Jeff Gilbert (jdashg) smaug: I'm really guessing at nouns here, haha!
Basically after set of JS calls, if one of them was a webgl call, I'd like to run code as we're returning to the event loop
<smaug> microtask runs at the end of outermost script execution, or at the end of the task.
jgilbert: ahaa, you don't want microtask ,but end-of-task?
<jgilbert> Jeff Gilbert (jdashg) it sounds like microtask would be fine
<mattwoodrow> jgilbert: https://searchfox.org/mozilla-central/source/dom/canvas/CanvasRenderingContext2D.cpp#1446
<jgilbert> Jeff Gilbert (jdashg) like "soon sometime after the current task"
<smaug> there can be several microtasks within a task
end-of-task model is different
our current StableState is basically end-of-task model
<jgilbert> Jeff Gilbert (jdashg) Is StableState "right after the Task is done"? Not "when done with queued tasks"?
<smaug> yes, it is after-the-task-is-done
in Gecko (but not anymore in the spec)
<jgilbert> Jeff Gilbert (jdashg) Is there a more spec-forward-compatible approach I should use?
<smaug> (in the spec stable state is one microtask basically)
jgilbert: are you implementing something from a spec?
<jgilbert> Jeff Gilbert (jdashg) No, but I would like it to keep working and not drift :)
If StableState is stable, that works
I just don't want weird bugs in a year
<smaug> but then hard to say what is correct. StableState is probably fine for now.
→ m_kato joined (m_kato@moz-flp.06r.120.61.IP)
<smaug> jgilbert: we don't let JS to run during StableState, or at least try to assert that
<jgilbert> Jeff Gilbert (jdashg) Specifically, if I call RunInStableState() in a RAF, it'll (probably) run before the next Present?
<smaug> Preset?
Present?
<jgilbert> Jeff Gilbert (jdashg) Present as in "presented to the compositor"
it's some DOM atomicity thing
<smaug> so, if you call RunInStableState during some rAF callback, the stablestate is handled after painting
<jgilbert> Jeff Gilbert (jdashg) I want to run a task between RAF and painting
<smaug> since the task is roughly [rAF callback, flush styling and layout, paint, end-of-task ]
ok, so you don't want end-of-task then :)
<jgilbert> Jeff Gilbert (jdashg) s/run a task/run a runnable/
ok
<smaug> sounds like microtask then
<jgilbert> Jeff Gilbert (jdashg) alright, thanks!
<smaug> there is a microtask checkpoint after each rAF callback
so, if there is such callback, microtask checkpoint is before style flush

So microtask after RAF doesn't help because the task directly after RAF is Paint. However, a heuristic for non-RAF (like requestPostAnimationFrame) would help. Really the best way to handle this would be an eager commit() call, though.

  • webgl.auto-flush (default: true) enqueues a runnable to flush pending
    webgl commands after each draw.
  • webgl.auto-flush.gl (default: false) causes this auto-flush to also
    call glFlush.

This is probably not useful for pure RAF-based apps, since they run
RAF();Present(); back-to-back. For other cases though, this should
improve latency and may reduce jank.

Assignee: nobody → jgilbert
Status: NEW → ASSIGNED
Pushed by jgilbert@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/03f2371bb998
Add webgl.auto-flush:true. r=lsalzman
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 93 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: