aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/timers.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2016-12-02 11:54:07 -0800
committerAnthony Ramine <n.oxyde@gmail.com>2017-03-03 23:25:29 +0100
commit4e7ac19380d7c24cc60d010dd8a43e5b020c371d (patch)
tree1a422cee2706c1fddb440b3f279cec124e7ab182 /components/script/timers.rs
parent198662f8cbbffa53de5a9d036a77934a36102134 (diff)
downloadservo-4e7ac19380d7c24cc60d010dd8a43e5b020c371d.tar.gz
servo-4e7ac19380d7c24cc60d010dd8a43e5b020c371d.zip
script: Use a timer when rAF is used for non-animation purposes
After this patch, when the page calls `requestAnimationFrame()` too many times in the row without actually mutating the DOM, further calls to `rAF` will actually perform the moral equivalent of `setTimeout(16)`. This saves a lot of CPU time compared to actually waiting for the vertical blanking interval, because waiting for that requires us to draw the page. Reduces CPU usage drastically on nytimes.com, which has a perpetual `requestAnimationFrame()` loop that checks whether ads are in view.
Diffstat (limited to 'components/script/timers.rs')
-rw-r--r--components/script/timers.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/components/script/timers.rs b/components/script/timers.rs
index 5de0dc2416b..c90a3fa5b1d 100644
--- a/components/script/timers.rs
+++ b/components/script/timers.rs
@@ -7,6 +7,7 @@ use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
use dom::bindings::reflector::DomObject;
use dom::bindings::str::DOMString;
+use dom::document::FakeRequestAnimationFrameCallback;
use dom::eventsource::EventSourceTimeoutCallback;
use dom::globalscope::GlobalScope;
use dom::testbinding::TestBindingCallback;
@@ -69,6 +70,7 @@ pub enum OneshotTimerCallback {
EventSourceTimeout(EventSourceTimeoutCallback),
JsTimer(JsTimerTask),
TestBindingCallback(TestBindingCallback),
+ FakeRequestAnimationFrame(FakeRequestAnimationFrameCallback),
}
impl OneshotTimerCallback {
@@ -78,6 +80,7 @@ impl OneshotTimerCallback {
OneshotTimerCallback::EventSourceTimeout(callback) => callback.invoke(),
OneshotTimerCallback::JsTimer(task) => task.invoke(this, js_timers),
OneshotTimerCallback::TestBindingCallback(callback) => callback.invoke(),
+ OneshotTimerCallback::FakeRequestAnimationFrame(callback) => callback.invoke(),
}
}
}