This file describes API surface changes made during experimentation. A first Origin Trial was carried out between M92–M94. No real feedback was shared by Google with other parties, incl. Intel. At the beginning of 2022, the ownership of the Compute Pressure API was transferred to Intel.
After research and discussions with interested parties (e.g., Google, Zoom, and others), we decided to make the following major changes to the API shape:
-
For better ergonomics, and due to security and fingerprinting concerns, the API interfaces have been redesigned to not use developer-configurable buckets, but instead output pressure changes as high level states.
-
Alignment with existing APIs: The Observer pattern used by the specification now more closely follows existing Observer based APIs on the web platform.
-
Partner requests: The APIs now work in iframes as well as workers (shared and dedicated) with proper security and privacy mitigations in place.
In a few words, the Compute Pressure API proposed for the new OT is more mature, stable, and has been re-designed to address security and fingerprinting concerns.
This explainer snapshot captures the older Compute Pressure API implemented in early experimentation.
function computePressureCallback(update) {
// The CPU base clock speed is represented as 0.5.
if (update.cpuSpeed >= 0.5 && update.cpuUtilization >= 0.9) {
// Dramatically cut down compute requirements to avoid overheating.
return;
}
// Options applied are returned with every update.
if (update.options.testMode) {
// The options applied may be different than those requested.
// E.g. the user agent may have reduced the number of thresholds observed.
console.log(`Utilization Thresholds: ${
JSON.stringify(update.options.cpuUtilizationThresholds)}`);
console.log(`Speed Thresholds: ${
JSON.stringify(update.options.cpuSpeedThresholds)}`);
}
}
const observer = new ComputePressureObserver(computePressureCallback, {
// Thresholds divide the interval [0.0 .. 1.0] into ranges.
cpuUtilizationThresholds: [0.75, 0.9, 0.5],
// The minimum clock speed is 0, and the maximum speed is 1. 0.5 maps to
// the base clock speed.
cpuSpeedThresholds: [0.5],
// Setting testMode to `true` will result in `computePressureCallback` to
// be invoked regularly even if no thresholds have been crossed. The
// computational data returned will not be informative, but this is useful
// for testing if the requested options have been accepted.
testMode: false,
});
observer.start();
The explainer and specification capture the latest vision for the API, implemented for further experimentation.
function pressureCallback(update) {
if (update.status === "critical") {
// Dramatically cut down compute requirements to avoid overheating.
return;
}
}
const observer = new PressureObserver(pressureCallback, { sampleInterval : 1_000 });
observer.observe('cpu');
sampleRate was renamed to sampleInterval and changed from Hz to ms.issue #253; Options are moved to the observe method. [issue #259] (w3c#259);
The explainer and specification capture the latest vision for the API, implemented for further experimentation.
function pressureCallback(update) {
if (update.status === "critical") {
// Dramatically cut down compute requirements to avoid overheating.
return;
}
}
const observer = new PressureObserver(pressureCallback);
observer.observe('cpu', { sampleInterval : 1_000 });