Skip to content

Improve decisions in compositor over when to draw a frame.#17398

Merged
bors-servo merged 3 commits intoservo:masterfrom
glennw:opt-composite
Jun 21, 2017
Merged

Improve decisions in compositor over when to draw a frame.#17398
bors-servo merged 3 commits intoservo:masterfrom
glennw:opt-composite

Conversation

@glennw
Copy link
Copy Markdown
Member

@glennw glennw commented Jun 19, 2017

This patch fixes a couple of issues in the compositor:

  1. Remove the delayed composition code. Previously, this would schedule
    a composite for 12ms in the future. This doesn't really make any sense
    with WR. There's no point in doing a composite unless WR has provided
    a new frame to be drawn. This fixes issues in several benchmarks where
    we were doing multiple composite / renders per rAF, which is a waste
    of CPU time. This does make the framerate slower in some cases (such
    as a slow rAF callback) but it's more correct - otherwise we were just
    compositing the same frame multiple times for no real benefit.

  2. Inform the window of the current animation state of the compositor.
    Specifically, if an animation (or rAF) is currently active, the
    window system switches to use event polling, and does not block on
    the OS-level event loop. In the case of active animation, we just
    assume that we want to be running as the vsync interval and not
    blocking. This means the compositor thread only sleeps on vsync
    during animation, which reduces OS scheduling and results in much
    smoother animation.


This change is Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jun 19, 2017
@glennw
Copy link
Copy Markdown
Member Author

glennw commented Jun 19, 2017

r? @pcwalton

I think the above comments are all correct, and this certainly results in smoother results and "correct" frame rates based on rAF, from what I've tested is. Nonetheless, changing things like this is quite subtle, and I might be missing something - so this could do with a careful look over!

@highfive highfive assigned pcwalton and unassigned metajack Jun 19, 2017
@glennw
Copy link
Copy Markdown
Member Author

glennw commented Jun 19, 2017

Thread profile before this change (showing multiple composites per rAF etc):

servo

Thread profile after this change - the parallelism is what I would expect to see, given the threads involved:

correct

@glennw
Copy link
Copy Markdown
Member Author

glennw commented Jun 19, 2017

cc @asajeffrey and @cbrewster since I think you've been working in this area and may have comments.

@glennw
Copy link
Copy Markdown
Member Author

glennw commented Jun 19, 2017

Fixed tidy error.

@pcwalton
Copy link
Copy Markdown
Contributor

@bors-servo: r+

@bors-servo
Copy link
Copy Markdown
Contributor

📌 Commit 36829da has been approved by pcwalton

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jun 19, 2017
@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit 36829da with merge d150e48...

bors-servo pushed a commit that referenced this pull request Jun 19, 2017
Improve decisions in compositor over when to draw a frame.

This patch fixes a couple of issues in the compositor:

1) Remove the delayed composition code. Previously, this would schedule
   a composite for 12ms in the future. This doesn't really make any sense
   with WR. There's no point in doing a composite unless WR has provided
   a new frame to be drawn. This fixes issues in several benchmarks where
   we were doing multiple composite / renders per rAF, which is a waste
   of CPU time. This *does* make the framerate slower in some cases (such
   as a slow rAF callback) but it's more correct - otherwise we were just
   compositing the same frame multiple times for no real benefit.

2) Inform the window of the current animation state of the compositor.
   Specifically, if an animation (or rAF) is currently active, the
   window system switches to use event polling, and does not block on
   the OS-level event loop. In the case of active animation, we just
   assume that we want to be running as the vsync interval and not
   blocking. This means the compositor thread only sleeps on vsync
   during animation, which reduces OS scheduling and results in much
   smoother animation.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17398)
<!-- Reviewable:end -->
@bors-servo
Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jun 19, 2017
@jdm
Copy link
Copy Markdown
Member

jdm commented Jun 19, 2017

{"status": "NOTRUN", "stack": null, "subtest": "Overall test", "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/canvas/buffer-offscreen-test.html", "line": 293680, "message": null, "expected": "PASS"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/canvas/buffer-offscreen-test.html", "line": 293685, "message": null, "expected": "OK"}
{"status": "NOTRUN", "stack": null, "subtest": "Overall test", "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/canvas/buffer-preserve-test.html", "line": 293797, "message": null, "expected": "PASS"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/canvas/buffer-preserve-test.html", "line": 293803, "message": null, "expected": "OK"}
{"status": "NOTRUN", "stack": null, "subtest": "Overall test", "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/canvas/framebuffer-bindings-unaffected-on-resize.html", "line": 294028, "message": null, "expected": "PASS"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/canvas/framebuffer-bindings-unaffected-on-resize.html", "line": 294039, "message": null, "expected": "OK"}
{"status": "NOTRUN", "stack": null, "subtest": "Overall test", "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/canvas/texture-bindings-unaffected-on-resize.html", "line": 294263, "message": null, "expected": "PASS"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/canvas/texture-bindings-unaffected-on-resize.html", "line": 294268, "message": null, "expected": "OK"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/extensions/oes-texture-float-with-canvas.html", "line": 296324, "message": null, "expected": "ERROR"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/extensions/oes-texture-half-float-with-canvas.html", "line": 296357, "message": null, "expected": "ERROR"}
{"status": "NOTRUN", "stack": null, "subtest": "Overall test", "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/extensions/webgl-compressed-texture-size-limit.html", "line": 296389, "message": null, "expected": "PASS"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/extensions/webgl-compressed-texture-size-limit.html", "line": 296391, "message": null, "expected": "OK"}
{"status": "NOTRUN", "stack": null, "subtest": "Overall test", "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/state/state-uneffected-after-compositing.html", "line": 325840, "message": null, "expected": "PASS"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/state/state-uneffected-after-compositing.html", "line": 325842, "message": null, "expected": "OK"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-canvas-rgb565.html", "line": 328225, "message": null, "expected": "ERROR"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-canvas-rgba4444.html", "line": 328235, "message": null, "expected": "ERROR"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-canvas-rgba5551.html", "line": 328717, "message": null, "expected": "ERROR"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-canvas.html", "line": 328853, "message": null, "expected": "ERROR"}
{"status": "NOTRUN", "stack": null, "subtest": "Overall test", "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-webgl-canvas-rgb565.html", "line": 329648, "message": null, "expected": "PASS"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-webgl-canvas-rgb565.html", "line": 329651, "message": null, "expected": "OK"}
{"status": "NOTRUN", "stack": null, "subtest": "Overall test", "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-webgl-canvas-rgba4444.html", "line": 329820, "message": null, "expected": "PASS"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-webgl-canvas-rgba4444.html", "line": 329823, "message": null, "expected": "OK"}
{"status": "NOTRUN", "stack": null, "subtest": "Overall test", "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-webgl-canvas-rgba5551.html", "line": 329841, "message": null, "expected": "PASS"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-webgl-canvas-rgba5551.html", "line": 329845, "message": null, "expected": "OK"}
{"status": "NOTRUN", "stack": null, "subtest": "Overall test", "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-webgl-canvas.html", "line": 329970, "message": null, "expected": "PASS"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-webgl-canvas.html", "line": 329973, "message": null, "expected": "OK"}
{"status": "NOTRUN", "stack": null, "subtest": "Overall test", "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/texture-size-limit.html", "line": 330387, "message": null, "expected": "PASS"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/webgl/conformance-1.0.3/conformance/textures/texture-size-limit.html", "line": 330451, "message": null, "expected": "OK"}
{"status": "TIMEOUT", "stack": null, "subtest": "Concurrent requestAnimationFrame loops are deterministic", "action": "test_result", "test": "/_mozilla/mozilla/deterministic-raf.html", "line": 340405, "message": "Test timed out", "expected": "PASS"}
{"status": "TIMEOUT", "stack": null, "subtest": null, "action": "test_result", "test": "/_mozilla/mozilla/deterministic-raf.html", "line": 340406, "message": null, "expected": "OK"}

gw3583 added 2 commits June 20, 2017 08:47
This patch fixes a couple of issues in the compositor:

1) Remove the delayed composition code. Previously, this would schedule
   a composite for 12ms in the future. This doesn't really make any sense
   with WR. There's no point in doing a composite unless WR has provided
   a new frame to be drawn. This fixes issues in several benchmarks where
   we were doing multiple composite / renders per rAF, which is a waste
   of CPU time. This *does* make the framerate slower in some cases (such
   as a slow rAF callback) but it's more correct - otherwise we were just
   compositing the same frame multiple times for no real benefit.

2) Inform the window of the current animation state of the compositor.
   Specifically, if an animation (or rAF) is currently active, the
   window system switches to use event polling, and does not block on
   the OS-level event loop. In the case of active animation, we just
   assume that we want to be running as the vsync interval and not
   blocking. This means the compositor thread only sleeps on vsync
   during animation, which reduces OS scheduling and results in much
   smoother animation.
yet considered spurious force a reflow / composite / animation tick cycle.
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Jun 20, 2017
@glennw
Copy link
Copy Markdown
Member Author

glennw commented Jun 20, 2017

Removing the delayed compositor timer exposed a bug in how we handle rAF callbacks that don't mutate the DOM. Added a second commit to handle that.

r? @jdm

@highfive highfive assigned jdm and unassigned pcwalton Jun 20, 2017
@glennw
Copy link
Copy Markdown
Member Author

glennw commented Jun 20, 2017

(or anyone else who knows the DOM code well enough to review that).

@jdm
Copy link
Copy Markdown
Member

jdm commented Jun 20, 2017

@bors-servo: r+

@bors-servo
Copy link
Copy Markdown
Contributor

📌 Commit 6c9e305 has been approved by jdm

@highfive highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 20, 2017
bors-servo pushed a commit that referenced this pull request Jun 20, 2017
Improve decisions in compositor over when to draw a frame.

This patch fixes a couple of issues in the compositor:

1) Remove the delayed composition code. Previously, this would schedule
   a composite for 12ms in the future. This doesn't really make any sense
   with WR. There's no point in doing a composite unless WR has provided
   a new frame to be drawn. This fixes issues in several benchmarks where
   we were doing multiple composite / renders per rAF, which is a waste
   of CPU time. This *does* make the framerate slower in some cases (such
   as a slow rAF callback) but it's more correct - otherwise we were just
   compositing the same frame multiple times for no real benefit.

2) Inform the window of the current animation state of the compositor.
   Specifically, if an animation (or rAF) is currently active, the
   window system switches to use event polling, and does not block on
   the OS-level event loop. In the case of active animation, we just
   assume that we want to be running as the vsync interval and not
   blocking. This means the compositor thread only sleeps on vsync
   during animation, which reduces OS scheduling and results in much
   smoother animation.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17398)
<!-- Reviewable:end -->
@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit 6c9e305 with merge 4530717...

@bors-servo
Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jun 20, 2017
@glennw
Copy link
Copy Markdown
Member Author

glennw commented Jun 20, 2017

@bors-servo r-

I'm seeing a few demos not animating correctly locally. I need to investigate more to see if it's related to this change.

This fixes another rAF bug, that is being exposed by the previous
two commits. Previously, the fake timer callback would only be
set if we were being called from a non-rAF event handler.

Now, if we're in fake / spurious mode, unconditionally set the one
shot timer.

Otherwise, notify the compositor that animations are present if
we're not currently in a rAF callback.
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Jun 21, 2017
@glennw
Copy link
Copy Markdown
Member Author

glennw commented Jun 21, 2017

Added a follow up commit that addresses an issue I ran into.

r? @jdm

@jdm
Copy link
Copy Markdown
Member

jdm commented Jun 21, 2017

@bors-servo: r+

@bors-servo
Copy link
Copy Markdown
Contributor

📌 Commit cbeb181 has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jun 21, 2017
@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit cbeb181 with merge 22ddd0f...

bors-servo pushed a commit that referenced this pull request Jun 21, 2017
Improve decisions in compositor over when to draw a frame.

This patch fixes a couple of issues in the compositor:

1) Remove the delayed composition code. Previously, this would schedule
   a composite for 12ms in the future. This doesn't really make any sense
   with WR. There's no point in doing a composite unless WR has provided
   a new frame to be drawn. This fixes issues in several benchmarks where
   we were doing multiple composite / renders per rAF, which is a waste
   of CPU time. This *does* make the framerate slower in some cases (such
   as a slow rAF callback) but it's more correct - otherwise we were just
   compositing the same frame multiple times for no real benefit.

2) Inform the window of the current animation state of the compositor.
   Specifically, if an animation (or rAF) is currently active, the
   window system switches to use event polling, and does not block on
   the OS-level event loop. In the case of active animation, we just
   assume that we want to be running as the vsync interval and not
   blocking. This means the compositor thread only sleeps on vsync
   during animation, which reduces OS scheduling and results in much
   smoother animation.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17398)
<!-- Reviewable:end -->
@bors-servo
Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-wpt4

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jun 21, 2017
@jdm
Copy link
Copy Markdown
Member

jdm commented Jun 21, 2017

@bors-servo: retry

  • servo-mac5 timed out on a bunch of builds but seems to be working fine now

@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit cbeb181 with merge 819a40b...

bors-servo pushed a commit that referenced this pull request Jun 21, 2017
Improve decisions in compositor over when to draw a frame.

This patch fixes a couple of issues in the compositor:

1) Remove the delayed composition code. Previously, this would schedule
   a composite for 12ms in the future. This doesn't really make any sense
   with WR. There's no point in doing a composite unless WR has provided
   a new frame to be drawn. This fixes issues in several benchmarks where
   we were doing multiple composite / renders per rAF, which is a waste
   of CPU time. This *does* make the framerate slower in some cases (such
   as a slow rAF callback) but it's more correct - otherwise we were just
   compositing the same frame multiple times for no real benefit.

2) Inform the window of the current animation state of the compositor.
   Specifically, if an animation (or rAF) is currently active, the
   window system switches to use event polling, and does not block on
   the OS-level event loop. In the case of active animation, we just
   assume that we want to be running as the vsync interval and not
   blocking. This means the compositor thread only sleeps on vsync
   during animation, which reduces OS scheduling and results in much
   smoother animation.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17398)
<!-- Reviewable:end -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Jun 21, 2017
@bors-servo
Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: jdm
Pushing 819a40b to master...

@bors-servo bors-servo merged commit cbeb181 into servo:master Jun 21, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants