Commit 65c561e
PerformanceObserver: default durationThreshold to 104ms (#56506)
Summary:
Pull Request resolved: #56506
React Native's `PerformanceObserver` previously defaulted `durationThreshold` to 0 for `event` entries, while the W3C Event Timing spec
(https://www.w3.org/TR/event-timing/#sec-modifications-perf-timeline) mandates a default of 104ms. The previous default flooded observers with short events
(clicks, pointer up/down) that are not interesting for responsiveness
measurement.
This change brings React Native in line with the spec by making 104ms the
default. The default is applied at the JSI bridge boundary in
`NativePerformance.cpp` (the JS API boundary on the C++ side) when JS does not
provide an explicit `durationThreshold`. The C++ public observer API
(`PerformanceObserverObserveSingleOptions::durationThreshold`) and the global
event buffer (`eventBuffer_.durationThreshold`) keep their `HighResDuration::zero()`
default — applying 104ms to the global buffer would drop sub-104ms events at
the source, breaking observers that explicitly request `durationThreshold: 0`.
Changes in `react-native`:
- `NativePerformance.cpp`: apply 104ms default at the JSI bridge boundary.
- `PerformanceApiExample.js` (rn-tester): pass `durationThreshold: 0` to
preserve previous behavior.
- `EventTimingAPI-itest.js`: migrate 4 existing call sites to
`{type: 'event', durationThreshold: 0}` and add a new test verifying the
104ms default.
Sites using `{entryTypes: ['event']}` were converted to
`{type: 'event', durationThreshold: 0}` since the spec (and existing JS
validation in `PerformanceObserver.js`) disallows `durationThreshold` together
with `entryTypes`.
Changelog: [General][Fixed] - PerformanceObserver: `observe({type: 'event'})` now correctly defaults `durationThreshold` to 104ms per the W3C Event Timing spec instead of reporting all events.
Reviewed By: hoxyq
Differential Revision: D101629586
fbshipit-source-id: 897914e8582a3d16db9e9388606be5d0aebd19ab1 parent 8944bb3 commit 65c561e
3 files changed
Lines changed: 61 additions & 6 deletions
File tree
- packages
- react-native
- ReactCommon/react/nativemodule/webperformance
- src/private/webapis/performance/__tests__
- rn-tester/js/examples/Performance
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
37 | 46 | | |
38 | 47 | | |
39 | 48 | | |
| |||
337 | 346 | | |
338 | 347 | | |
339 | 348 | | |
340 | | - | |
| 349 | + | |
341 | 350 | | |
342 | 351 | | |
343 | 352 | | |
| |||
Lines changed: 50 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| |||
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
344 | 390 | | |
345 | 391 | | |
346 | 392 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| |||
0 commit comments