Skip to content

Commit 9583464

Browse files
committed
[iOS] Throttle DOM timers to 30fps in low power mode
https://bugs.webkit.org/show_bug.cgi?id=169213 <rdar://problem/30876965> Reviewed by Simon Fraser. Source/WebCore: Throttle and align DOM timers to ~30fps in low power mode on iOS to save battery. Test: fast/dom/timer-throttling-lowPowerMode.html * page/DOMTimer.h: * page/Page.cpp: (WebCore::Page::handleLowModePowerChange): (WebCore::Page::updateDOMTimerAlignmentInterval): LayoutTests: Add layout test coverage. * fast/dom/timer-throttling-lowPowerMode-expected.txt: Added. * fast/dom/timer-throttling-lowPowerMode.html: Added. Canonical link: https://commits.webkit.org/186348@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213589 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 2892ccb commit 9583464

6 files changed

Lines changed: 107 additions & 1 deletion

File tree

LayoutTests/ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2017-03-08 Chris Dumez <cdumez@apple.com>
2+
3+
[iOS] Throttle DOM timers to 30fps in low power mode
4+
https://bugs.webkit.org/show_bug.cgi?id=169213
5+
<rdar://problem/30876965>
6+
7+
Reviewed by Simon Fraser.
8+
9+
Add layout test coverage.
10+
11+
* fast/dom/timer-throttling-lowPowerMode-expected.txt: Added.
12+
* fast/dom/timer-throttling-lowPowerMode.html: Added.
13+
114
2017-03-08 Ryan Haddad <ryanhaddad@apple.com>
215

316
Mark editing/selection/move-by-word-visually-multi-space.html as flaky on Sierra Debug WK2.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Tests that DOM timers are throttled in low power mode.
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
Enabling low power mode
7+
internals.setLowPowerModeEnabled(true)
8+
* Nesting: 1
9+
PASS internals.isTimerThrottled(timerHandle) is false
10+
* Nesting: 2
11+
PASS internals.isTimerThrottled(timerHandle) is false
12+
* Nesting: 3
13+
PASS internals.isTimerThrottled(timerHandle) is false
14+
* Nesting: 4
15+
PASS internals.isTimerThrottled(timerHandle) is false
16+
* Nesting: 5
17+
PASS internals.isTimerThrottled(timerHandle) is true
18+
* Nesting: 6
19+
PASS internals.isTimerThrottled(timerHandle) is true
20+
21+
Disabling low power mode
22+
internals.setLowPowerModeEnabled(false)
23+
* Nesting: 7
24+
PASS internals.isTimerThrottled(timerHandle) is false
25+
* Nesting: 8
26+
PASS internals.isTimerThrottled(timerHandle) is false
27+
* Nesting: 9
28+
PASS internals.isTimerThrottled(timerHandle) is false
29+
* Nesting: 10
30+
PASS internals.isTimerThrottled(timerHandle) is false
31+
PASS successfullyParsed is true
32+
33+
TEST COMPLETE
34+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<script src="../../resources/js-test-pre.js"></script>
5+
<script>
6+
description("Tests that DOM timers are throttled in low power mode.");
7+
jsTestIsAsync = true;
8+
9+
let i = 0;
10+
const maxNestingLevel = 5;
11+
12+
let lowPowerModeEnabled = true;
13+
debug("Enabling low power mode");
14+
evalAndLog("internals.setLowPowerModeEnabled(true)");
15+
16+
const timerHandle = setInterval(function() {
17+
i++;
18+
debug("* Nesting: " + i);
19+
if (i >= maxNestingLevel && lowPowerModeEnabled)
20+
shouldBeTrue("internals.isTimerThrottled(timerHandle)");
21+
else
22+
shouldBeFalse("internals.isTimerThrottled(timerHandle)");
23+
24+
if (i == maxNestingLevel + 1) {
25+
debug("");
26+
debug("Disabling low power mode");
27+
lowPowerModeEnabled = false;
28+
evalAndLog("internals.setLowPowerModeEnabled(false)");
29+
}
30+
31+
if (i == 10) {
32+
clearInterval(timerHandle);
33+
finishJSTest();
34+
}
35+
}, 10);
36+
</script>
37+
<script src="../../resources/js-test-post.js"></script>
38+
</body>
39+
</html>

Source/WebCore/ChangeLog

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2017-03-08 Chris Dumez <cdumez@apple.com>
2+
3+
[iOS] Throttle DOM timers to 30fps in low power mode
4+
https://bugs.webkit.org/show_bug.cgi?id=169213
5+
<rdar://problem/30876965>
6+
7+
Reviewed by Simon Fraser.
8+
9+
Throttle and align DOM timers to ~30fps in low power mode on iOS
10+
to save battery.
11+
12+
Test: fast/dom/timer-throttling-lowPowerMode.html
13+
14+
* page/DOMTimer.h:
15+
* page/Page.cpp:
16+
(WebCore::Page::handleLowModePowerChange):
17+
(WebCore::Page::updateDOMTimerAlignmentInterval):
18+
119
2017-03-08 Chris Dumez <cdumez@apple.com>
220

321
Update outdated comment about HTMLElement.dropzone

Source/WebCore/page/DOMTimer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class DOMTimer final : public RefCounted<DOMTimer>, public SuspendableTimer {
4747

4848
static Seconds defaultMinimumInterval() { return 4_ms; }
4949
static Seconds defaultAlignmentInterval() { return 0_s; }
50+
static Seconds defaultAlignmentIntervalInLowPowerMode() { return 30_ms; }
5051
static Seconds hiddenPageAlignmentInterval() { return 1_s; }
5152

5253
// Creates a new timer owned by specified ScriptExecutionContext, starts it

Source/WebCore/page/Page.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ void Page::handleLowModePowerChange(bool isLowPowerModeEnabled)
11381138
{
11391139
updateScriptedAnimationsThrottlingReason(*this, isLowPowerModeEnabled ? ThrottlingReasonOperation::Add : ThrottlingReasonOperation::Remove, ScriptedAnimationController::ThrottlingReason::LowPowerMode);
11401140
mainFrame().animation().updateThrottlingState();
1141+
updateDOMTimerAlignmentInterval();
11411142
}
11421143

11431144
void Page::userStyleSheetLocationChanged()
@@ -1349,7 +1350,7 @@ void Page::updateDOMTimerAlignmentInterval()
13491350

13501351
switch (m_timerThrottlingState) {
13511352
case TimerThrottlingState::Disabled:
1352-
m_domTimerAlignmentInterval = DOMTimer::defaultAlignmentInterval();
1353+
m_domTimerAlignmentInterval = isLowPowerModeEnabled() ? DOMTimer::defaultAlignmentIntervalInLowPowerMode() : DOMTimer::defaultAlignmentInterval();
13531354
break;
13541355

13551356
case TimerThrottlingState::Enabled:

0 commit comments

Comments
 (0)