This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 10633 - Minimums for timer granularity should be left to the user agent - different form factors have different power requirements
Summary: Minimums for timer granularity should be left to the user agent - different f...
Status: RESOLVED FIXED
Alias: None
Product: HTML WG
Classification: Unclassified
Component: pre-LC1 HTML5 spec (editor: Ian Hickson) (show other bugs)
Version: unspecified
Hardware: All All
: P3 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: HTML WG Bugzilla archive list
URL: http://dev.w3.org/html5/spec/timers.h...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-15 01:55 UTC by Adrian Bateman [MSFT]
Modified: 2010-10-04 13:58 UTC (History)
4 users (show)

See Also:


Attachments

Description Adrian Bateman [MSFT] 2010-09-15 01:55:21 UTC
Summary 

The HTML5 spec contains the following section

"6.2 Timers
Note: This API does not guarantee that timers will fire exactly on schedule. Delays due to CPU load, other tasks, etc, are to be expected.
... 
The setTimeout() method must run the following steps:
... 
5. If the currently running task is a task that was created by the setTimeout() method, and timeout is less than 4, then increase timeout to 4.
... 
The setInterval() method must run the following steps:
... 
	5. If timeout is less than 10, then increase timeout to 10."

We propose removing the exact timeout values from the spec for the following reasons:
1. Many architectures and computing platforms are unlikely to support these timeout values.
2. The provided timeout values can have a very negative impact on power consumption and battery life
3. Every major released and pre-release browser implements different setTimeout and setInterval behavior and don't adhere to the timeout values provided


Rationale

Even though the spec clearly states that timers aren't guaranteed to fire exactly on schedule, the spec does set the expectation for web developers that a setTimeout of 4ms can be expected to work and only occasionally not fire precisely at the given timeout. 

Many mobile architecture and platforms are aggressive with regards to power consumption and battery life times. Consequently, they do not allow callbacks with timeouts of 4ms or even 10ms. 

The impact on battery life time can be significant: 

Energy Smart Software[1] page 6:
"The default Windows 7 timer resolution is 15.6 milliseconds (ms), which allows the processor to make effective use of C-states when the system is not heavily loaded. The highest timer resolution available on most modern systems is 1ms. Setting the timer resolution to 1ms on a modern system can increase power consumption by 15 percent. For a typical client scenario of a modern laptop that is being used to browse the web and to do light processing, setting the timer to 1 ms could reduce battery run time by more than an hour."

Furthermore, frequent periodic executions are detrimental to power consumption since it prevents processors and surrounding components from entering power conservation states and the overhead of entering and exiting power states frequently negates any power savings. It is more optimal to execute a burst of computation followed by a long idle time during which cores and other chipset components can be turned off:

CPU Power Utilization on Intel Architectures [2]:
"Every interrupt will pull back the CPU from a deeper sleep state to C0 due to the interrupt handler that services the interrupts. This impacts the sleep state residencies that are critical to optimize the power consumed. There is also an energy cost associated in transitioning between multiple C-states. If the interrupt rates are high, the power savings due to deeper sleep states are negatively impacted due to the decrease in sleep state residencies and the cost associated with C-state transitions. While IntelĀ® platforms offer platform-specific C3-like states, they require long residency (multiple milliseconds) to fully amortize their transitional costs. An aggressive interrupt rate can potentially negate the benefits of deep sleep states offered by the platform."


Details

The bullet 5 in the setTimeout part of section "6.2 Timers" should be changed to:

5. If the currently running task is a task that was created by the setTimeout() method, and timeout is less than a user-agent-defined value, then increase timeout to the user-agent-defined value.
	
As well as the bullet 5 in the setInterval part of the same section should be changed to:

5. If timeout is less than a user-agent-defined value, then increase timeout to the user-agent-defined value.


Impact

Positive Impact
* Not prescribing specific timeout values avoid setting expectations with web developers that certain timeouts can be achieved on all architectures and platforms
* Removing the prescribed timeouts allows browser vendors to create implementations that are power conscious, conserve battery lifetime and reduce power consumption ultimately impacting world energy consumption
* Allows browser vendors to implement HTML5 conforming browsers on platforms that cannot meet the currently prescribed values as well as meet power restrictions.

Negative Impact
* Implementation will not converge on implementation, but that is unlikely to happen due to different architecture constraints

Risks

Considering that more major browsers do not adhere to the currently prescribes timeout values, removing the values entirely from the spec should not impact existing web pages. 


References

[1] Energy Smart Software (June 16, 2010) 
http://www.microsoft.com/whdc/system/pnppwr/powermgmt/Energy-Smart_SW.mspx 

[2] CPU Power Utilization on Intel Architectures
http://software.intel.com/en-us/articles/cpu-power-utilization-on-intel-architectures/
Comment 1 Ian 'Hixie' Hickson 2010-09-28 22:07:58 UTC
EDITOR'S RESPONSE: This is an Editor's Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Partially Accepted
Change Description: see diff given below
Rationale: I've added clauses specifically for handling low-power devices such as the above. I don't want to remove the explicit numbers, because in practice those are the minimum values that are required for interoperability with legacy content, and that is useful information for implementors.