Skip to content

requestAnimationFrame is called ~1500 times per second #7782

Closed

Description

@paulrouget

Which is a little bit too much :)

<script>
  var count = 0;
  function step() {
    count++;
    requestAnimationFrame(step);
  }

  setInterval(function() {
    document.body.textContent = count + "FPS";
    count = 0;
  }, 1000);

  step();
</script>

Activity

  1. glennw commented on Sep 29, 2015

    @glennw
    Member

    Yep - I ran across this yesterday. The callback is triggered whenever the compositor runs, which is as fast as possible when animations are running (which is also wrong). Instead, it should only trigger the callback after an entire paint completes for the relevant pipeline. This is a little bit tricky, since it needs to check the epoch for each layer that is painted for the pipeline in question.

  2. added
    E-more-complex
    I-wrong
    on Sep 29, 2015
  3. Yoric commented on Sep 29, 2015

    @Yoric
    Contributor

    @glennw I'd like to work on this, if you can give me a hand.

    I am trying to understand to follow the chain that triggers the callback. As I understand, this goes through ConstellationControlMsg::TickAllAnimations, which we want to send less often. In turn this goes through LayoutControlMsg::TickAnimations, ConstellationControMsg::TickAnimations and to change_running_animations_state. Is this where we want to throttle the callback or should I climb the chain a little bit further?

  4. paulrouget commented on Sep 29, 2015

    @paulrouget
    ContributorAuthor

    The callback is triggered whenever the compositor runs, which is as fast as possible when animations are running (which is also wrong).

    In my case, there was no animation.

    Instead, it should only trigger the callback after an entire paint completes for the relevant pipeline.

    What is wrong with keeping the same strategy (RFA when the compositor runs), but driving the compositor with vsync? Isn't that how it's supposed to work?

  5. glennw commented on Sep 29, 2015

    @glennw
    Member

    @paulrouget If we drive it with vsync we could get extra callbacks when the repainting is taking longer than a vsync period, and we should also support running in non-vsync mode correctly, I think.

    @Yoric Great! I think what we want to do is throttle the callback in process_animations which is called each time the compositor draws a frame - in such a way that it only ticks animations if there isn't an outstanding paint being waited on for the relevant pipeline.

    @pcwalton Does that sound correct to you?

  6. Yoric commented on Sep 30, 2015

    @Yoric
    Contributor

    According to my trusty Gecko Compositor hacker @nical, we should really drive it with vsync. Preventing double-callbacks shouldn't be too hard, I guess.

    @glennw Why do we want to support non-vsync mode, btw?

  7. nical commented on Sep 30, 2015

    @nical
    Contributor

    Non-vsync mode is useful if you want to benchmark layout or rendering performance, but it's important for frame uniformity to drive RaF from vsyncs in the general case. Better yet, detecting that we are not keeping up with vsync and skipping every other vsyncs when that happens to keep frames uniforms (or when we want to save energy) is pretty useful.
    It should not be hard to avoid the extra callback problem (you more or less just need to ignore incoming vsync notifications when you have a vsync callback that hasn't completed yet).

  8. glennw commented on Sep 30, 2015

    @glennw
    Member

    @Yoric Yep, exactly what nical said. I should have been clearer in saying that driving it from vsync is what we want, we just need to take account of those edge cases (vsync disabled, and painting not keeping up with vsync) and make sure they work too.

  9. Yoric commented on Oct 1, 2015

    @Yoric
    Contributor

    @glennw Oh, so we have vsync support already?

  10. glennw commented on Oct 1, 2015

    @glennw
    Member

    @Yoric Only in so much as (I think) we set the default swap interval to vsync - it may even just be that it defaults to vsync on my linux machine.

  11. Yoric commented on Oct 2, 2015

    @Yoric
    Contributor

    I'm a bit lost. If process_animations is called 1500 times per second, then so are process_pending_scroll_events and window.present() (which I understand is window flipping: documentation needed), so I guess we need to throttle all of these to vsync. Are you telling me that this is probably already the case at least on Linux?

    If so, your earlier comment is a fallback for platforms that do not have vsync, right? I'm not sure I understand why finding out if the pipeline is waiting for a paint is related to the issue at hand (unless that's the vsync?) but I can certainly investigate this. Is this what does_layer_have_outstanding_paint_messages does or should I look on the other side of the pipeline?

  12. nical commented on Oct 2, 2015

    @nical
    Contributor

    Yoric already knows about this document, but for the record, here is the design doc of the vsync stuff in gecko: https://dxr.mozilla.org/mozilla-central/source/gfx/doc/Silk.md

  13. added a commit that references this issue on Oct 2, 2015
    a3b5384
  14. 7 remaining items

  15. glennw commented on Jan 22, 2016

    @glennw
    Member

    I pushed glennw@be3213e to the WR servo branch. In my test case, with vsync enabled (which is the default), I am getting rAF callbacks at exactly 60 fps, synced with the presentation interval.

    I've also opened a PR to submit this to upstream servo here - #9401 - however even once this lands upstream there may be issues with non-WR painting backend in some cases.

  16. paulrouget commented on Jan 22, 2016

    @paulrouget
    ContributorAuthor

    @glennw on osx, I'm still getting ~500 calls.

  17. glennw commented on Jan 22, 2016

    @glennw
    Member

    It sounds like maybe vsync isn't working? Is there any way to verify if an application is running with vsync enabled?

  18. paulrouget commented on Jan 22, 2016

    @paulrouget
    ContributorAuthor

    I added to comment 0 the script I use to count the FPS.

  19. glennw commented on Jan 22, 2016

    @glennw
    Member

    I tried that test case on Linux and it's reporting 60 fps (well 61-62 but close enough for this test).

  20. paulrouget commented on Jan 25, 2016

    @paulrouget
    ContributorAuthor

    vsync is enabled on mac (at least, glutin's WindowBuilder::with_vsync is called).

  21. paulrouget commented on Jan 26, 2016

    @paulrouget
    ContributorAuthor

    Actually - I was wrong. It runs at 60 FPS.
    Sorry sorry. I must have run a release build and compiled a debug build.

  22. paulrouget commented on Jan 26, 2016

    @paulrouget
    ContributorAuthor

    I figured it out. Using the -b option makes the FPS go crazy. Not using -b, it goes at 60 FPS.

  23. paulrouget commented on Jan 26, 2016

    @paulrouget
    ContributorAuthor
  24. pcwalton commented on Jan 27, 2016

    @pcwalton
    Contributor

    @paulrouget Can we close this in favor of #9431?

  25. paulrouget commented on Jan 27, 2016

    @paulrouget
    ContributorAuthor

    @pcwalton This issue will get fixed once #9244 lands.

  26. paulrouget commented on Jan 27, 2016

    @paulrouget
    ContributorAuthor

    Sorry, I meant when #9401 lands.

  27. paulrouget commented on Jan 28, 2016

    @paulrouget
    ContributorAuthor

    (not a browserhtml-P1 anymore as it has been fixed in webrender)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-gfx/compositingI-wrong

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions