@@ -3,26 +3,288 @@ Title: CPU Performance API
33Shortname : cpu-performance
44Level : None
55Status : w3c/UD
6- Repository : explainers-by-googlers /cpu-performance
7- URL : https://explainers-by-googlers .github.io/cpu-performance
6+ Repository : WICG /cpu-performance
7+ URL : https://wicg .github.io/cpu-performance/
88Editor : Nikolaos Papaspyrou, Google https://google.com, nikolaos@google.com
9- Abstract : Expose some information about how powerful the user device is. This API targets web applications that will use this information to provide an improved user experience, possibly in combination with the Compute Pressure API, which provides information about the user device’s CPU pressure/utilization and allows applications to react to changes in CPU pressure.
9+ Abstract : This document defines a simple web API which exposes some
10+ information about how powerful the user device is. It targets web
11+ applications that will use this static information to provide an
12+ improved user experience, possibly in combination with the Compute
13+ Pressure API, which provides dynamic information about the user
14+ device's CPU pressure/utilization and allows applications to react
15+ to changes in CPU pressure.
1016Markup Shorthands : markdown yes, css no
1117Complain About : accidental-2119 yes, missing-example-ids yes
1218Assume Explicit For : yes
1319Die On : warning
14- WPT Path Prefix : TODO-API-LABEL
15- WPT Display : closed
20+ WPT Path Prefix : cpu-performance
21+ WPT Display : open
1622Include MDN Panels : if possible
1723Include Can I Use Panels : yes
1824</pre>
1925
2026Introduction {#intro}
2127=====================
2228
23- For now, see the <a href=[REPOSITORYURL]>explainer</a> .
29+ *This section is non-normative.*
2430
25- See [https://garykac.github.io/procspec/] (https://garykac.github.io/procspec/),
26- [https://dlaliberte.github.io/bikeshed-intro/index.html] (https://dlaliberte.github.io/bikeshed-intro/index.html),
27- and [https://speced.github.io/bikeshed/] (https://speced.github.io/bikeshed/) to get started on your
28- specification.
31+ There has always been developer interest for adapting web content, based
32+ on how powerful the user device is. E.g., video-conferencing applications
33+ or video games may use this information to decide if advanced video effects
34+ can be rendered; all types of applications may use it to decide whether to
35+ attempt running AI tasks locally or delegate to the server, etc.
36+
37+ In particular, web applications may want to use performance information to:
38+
39+ 1. Control non-essential tasks and requests; e.g.,
40+ allow or block 3rd party scripts,
41+ use or avoid heavy libraries.
42+ 2. Adjust the complexity of web content; e.g.,
43+ the resolution and format for images and video,
44+ the compression level for uploading data,
45+ enable or disable computationally heavy operations such as animations,
46+ improve resource management (lazy loading, prefetching, prerendering).
47+ 3. Improve real user monitoring; e.g.,
48+ better understand if users have faster or slower devices,
49+ focus development effort more appropriately.
50+ 4. Run computations on the client side vs. on the server side; e.g.,
51+ use server-side rendering,
52+ run AI applications and LLMs on the client side.
53+ 5. Select ads that are better suited for the user device.
54+
55+
56+ CPU Performance {#cpu_performance}
57+ ==================================
58+
59+ Modern computing devices often integrate multiple, heterogeneous
60+ *processing units*, differing in their nature and capabilities.
61+ The Central Processing Unit (CPU) is the central component in every
62+ computing device.
63+ Modern computing devices contain a number of integrated circuits (multi-core
64+ processors), each containing a number of <dfn lt='physical core'>physical
65+ cores</dfn> that operate as independent CPUs.
66+ Furthermore, technologies for simultaneous multi-threading (or hyper-threading)
67+ allow [=physical cores=] to handle multiple instruction threads, thus appearing
68+ as multiple separate <dfn lt='logical core'>logical cores</dfn> to the
69+ operating system.
70+
71+ Beyond CPU, modern computers may comprise other types of processing units,
72+ such as:
73+
74+ - Graphics Processing Units (GPU) for handling complex graphics, video,
75+ and computationally intensive tasks in parallel, like scientific simulations
76+ and AI training;
77+ - Neural Processing Units (NPU) or Tensor Processing Units (TPU) for improving
78+ performance in AI and machine learning tasks;
79+ - Digital Signal Processors (DSP) for optimizing the real-time processing of
80+ signals;
81+ - Field-Programmable Gate Arrays (FPGA) for optimizing specific tasks via
82+ custom accelerators implemented with reconfigurable, programmable hardware,
83+ etc.
84+
85+ This specification currently addresses the Central Processing Unit only,
86+ aiming to expose a measure of its performance to web applications.
87+ Future versions of this specification may also address other types of
88+ processing units.
89+
90+ We will use the term <dfn>CPU</dfn> for the collection of central processing
91+ units that are contained in a computing device.
92+ We will use the term <dfn>core</dfn> to refer to a [=CPU=] part that can execute
93+ instruction threads, [=physical cores|physical=] or [=logical cores|logical=] ,
94+ as reported by the operating system. We will use the term <dfn>frequency</dfn>
95+ to refer to the clock speed of the [=CPU=] , expressed in cycles per second (Hz)
96+ and determining how fast a [=physical core=] can execute instructions.
97+
98+ We will use the term <dfn>performance</dfn> to refer to how fast the [=CPU=] is
99+ perceived to be, from the point of view of a web application. A fast [=CPU=]
100+ handles tasks quicker, e.g., leading to faster application loading, better
101+ multitasking, smoother gaming, etc.
102+
103+
104+ Performance Tiers {#tiers}
105+ ==========================
106+
107+ The CPU Performance API classifies user devices according to their [=CPU=]
108+ [=performance=] in a small number of <dfn lt='performance tier'>performance
109+ tiers</dfn> . Each [=performance tier=] is represented by a small positive
110+ integer number. Higher values correspond to higher [=performance tiers=] , i.e.,
111+ to more powerful user devices.
112+
113+ There are four distinct [=performance tiers=] , numbered 1–4. Applications using
114+ the API should handle additional [=performance tiers|tiers=] (numbered 5 and
115+ above) which are likely to be added in the future as devices improve over time.
116+
117+ The special value 0 (zero) corresponds to an unknown [=performance tier=] ,
118+ returned in case the API's implementation is unable to classify the user device.
119+
120+
121+ ## Computing Performance Tier Value ## {#computing-performance-tier-value}
122+
123+ Classification of user devices to [=performance tiers=] is
124+ [=implementation-defined=] and should be interpreted by web applications
125+ according to their particular needs. However, implementations of this API should
126+ adhere to the following rules:
127+
128+ 1. **Consistency**: The mapping of devices to [=performance tiers=] should
129+ reflect the [=CPU=] [=performance=] that can be measured with specific
130+ benchmarks, ideally using programming tools provided by a browser
131+ (JavaScript, WebAssembly, etc.) and measured in ideal conditions. More
132+ powerful devices should not be classified in lower [=performance tiers=]
133+ than less powerful devices.
134+
135+ 2. **Reproducibility**: An implementation should always report the same
136+ [=performance tier=] for the same user device. In particular:
137+
138+ - The reported [=performance tier=] should not depend on the user device's
139+ current load or utilization; and
140+ - Implementations should not redefine [=performance tiers|tiers=] ; that
141+ is, [=performance tier|tier=] 4 devices should not be reclassified as
142+ [=performance tier|tier=] 3 to accommodate newer, higher-powered devices
143+ as technology improves. Instead, a new [=performance tier|tier=] 5
144+ will be added to this specification for those newer devices, when the
145+ need arises, and then a [=performance tier|tier=] 6 and so on.
146+
147+ NOTE: The intention of this rule is not to make it impossible to fix
148+ classification mistakes in implementations of this API. Such mistakes
149+ will inevitably have to be fixed. Rather, the intention of the rule is
150+ not to reclassify CPU models with new technology emerging, so as not to
151+ break the behavior of obsolete machines running obsolete applications.
152+
153+ 3. **User privacy**: To avoid user fingerprinting, implementations should
154+ classify a fairly large number of user devices in each [=performance tier=]
155+ (see also [[#security-privacy]] ). In particular, implementations that are
156+ based on some [=CPU=] model database should not return the special value 0
157+ for new user devices that are not contained in the database. The special
158+ value should be returned only when the implementation cannot obtain
159+ information about the [=CPU=] from the operating system.
160+
161+ Implementations may (but are not required to) compute the [=performance tier=]
162+ value for a given user device based on the following characteristics:
163+
164+ - the [=CPU=] model;
165+ - the number of [=cores=] , [=physical core|physical=] and/or [=logical
166+ core|logical=] ;
167+ - the [=frequency=] ; and
168+ - other available [=CPU=] characteristics.
169+
170+
171+ Javascript API {#js-api}
172+ ========================
173+ <xmp class="idl">
174+ [
175+ SecureContext,
176+ Exposed=Window
177+ ] partial interface Navigator {
178+ readonly attribute unsigned short cpuPerformance;
179+ };
180+ </xmp>
181+
182+ <div algorithm>
183+ The <dfn attribute for=Navigator><code>cpuPerformance</code></dfn> getter
184+ steps are:
185+
186+ 1. Let |tier| be an {{unsigned short}} representing the [=performance
187+ tier=] of the device's [=CPU=] , generated in an
188+ [=implementation-defined=] way, considering the recommendations
189+ and constraints described in [[#computing-performance-tier-value]] .
190+ 2. [=Assert=] : 0 ≤ |tier| ≤ 4.
191+ 3. Return |tier|.
192+ </div>
193+
194+
195+ Security and Privacy Considerations {#security-privacy}
196+ =======================================================
197+
198+ The CPU Performance API will only be available to HTTPS secure contexts.
199+
200+ To reduce fingerprinting risk, the CPU Performance API does not reveal [=CPU=]
201+ characteristics directly. The reported value is a small integer number that
202+ represents the [=performance tier=] corresponding to the [=CPU=] . For each
203+ possible value ([=performance tier|tier=] ), implementations should ensure that a
204+ fairly large number of computing devices existing on the internet at any given
205+ time, both as an absolute number and as distinct [=CPU=] models, are classified
206+ as having this [=performance tier=] . In particular, the intention of this
207+ specification is that each [=performance tier=] should contain no less than 10%
208+ of the existing [=CPU=] models, and no less than 10% of the existing user
209+ devices at any given time.
210+
211+ See also the [TAG Security/Privacy Questionnaire] (security-privacy-questionnaire.md).
212+
213+
214+ Example {#example}
215+ ==================
216+
217+ *This section is non-normative.*
218+
219+ A video conferencing application could interpret the four [=performance tiers=]
220+ as follows. This interpretation is application specific and, even then, it may
221+ have to be updated in the future if the application itself is updated and its
222+ hardware requirements change.
223+
224+ - 1: devices that are practically unusable for video calls;
225+ - 2: underpowered devices but still adequately suited for video calls;
226+ - 3: devices that can comfortably accommodate video calls; and
227+ - 4: devices that can run even the most demanding scenarios and have
228+ performance to spare for multitasking.
229+
230+ Such an application could use the value of `navigator.cpuPerformance`
231+ for pre-selecting a number of features that are best supported by the
232+ user device's [=performance tier=] .
233+
234+ <div class="example" id="example-1">
235+ <pre class="highlight lang-javascript">
236+ function getPresetFeatures() {
237+ switch (navigator.cpuPerformance) {
238+ case 1:
239+ return {
240+ videoQuality: "QVGA",
241+ frameRate: 15,
242+ effects: [],
243+ };
244+ case 2:
245+ return {
246+ videoQuality: "VGA",
247+ frameRate: 15,
248+ effects: ['voice-detection', 'animated-reactions'] ,
249+ };
250+ case 3:
251+ return {
252+ videoQuality: "720p",
253+ frameRate: 30,
254+ effects: ['voice-detection' , 'animated-reactions' ,
255+ 'noise-reduction' ],
256+ };
257+ case 4:
258+ case 0: // Assuming high performance settings for unknown devices
259+ default: // and for performance tiers higher than 4.
260+ return {
261+ videoQuality: "1080p",
262+ frameRate: 30,
263+ effects: ['voice-detection' , 'animated-reactions' ,
264+ 'noise-reduction' , 'virtual-background' ],
265+ };
266+ }
267+ }
268+ </pre>
269+ </div>
270+
271+
272+ Acknowledgements {#acknowledgements}
273+ ====================================
274+
275+ Many thanks for valuable feedback and advice from:
276+ Dominic Farolino,
277+ Deepti Gandluri,
278+ Reilly Grant,
279+ Tomas Gunnarsson,
280+ Markus Handell,
281+ Michael Lippautz,
282+ Thomas Nattestad,
283+ Nicola Tommasi,
284+ Guido Urdaneta,
285+ Måns Vestin,
286+ and
287+ Chen Xing.
288+
289+ Thanks to the W3C Web Performance Working Group (WebPerf) and especially
290+ Yoav Weiss.
0 commit comments