Commit 2d237d0
Expand structuredClone compatibility and benchmarks (#58735)
Summary:
Compare React Native structuredClone with ungap/structured-clone (**used by Expo**) and port the applicable upstream coverage. Add support for ArrayBuffer, DataView, typed arrays, boxed BigInt values, Error subclasses, deeply cloned causes, and safe __proto__ data properties. Serialization-only and JSON/lossy tests remain out of scope because React Native exposes a single-step cloning API.
Add ungap/structured-clone as a devDependency and benchmark each existing Fantom scenario against it.
Before — React Native implementation before this change:
### structuredClone (mode 🚀) ###
| (index) | Task name | Latency avg (ns) | Latency med (ns) | Throughput avg (ops/s) | Throughput med (ops/s) | Samples |
| ------- | ------------------------ | ----------------- | ---------------- | ---------------------- | ---------------------- | ------- |
| 0 | 'clone a string' | '338.62 ± 0.05%' | '330.00 ± 9.00' | '3014547 ± 0.05%' | '3030303 ± 84962' | 2953184 |
| 1 | 'clone a basic array' | '1587.6 ± 10.36%' | '1353.0 ± 19.00' | '734465 ± 0.42%' | '739098 ± 10235' | 638616 |
| 2 | 'clone a basic object' | '1344.2 ± 8.81%' | '1172.0 ± 20.00' | '828917 ± 0.33%' | '853242 ± 14813' | 743963 |
| 3 | 'clone a complex object' | '3370.6 ± 0.60%' | '3255.0 ± 40.00' | '304183 ± 0.02%' | '307220 ± 3822' | 296680 |
After — React Native compared with ungap/structured-clone:
### structuredClone (mode 🚀) ###
| (index) | Task name | Latency avg (ns) | Latency med (ns) | Throughput avg (ops/s) | Throughput med (ops/s) | Samples |
| ------- | -------------------------------------- | ----------------- | ----------------- | ---------------------- | ---------------------- | ------- |
| 0 | 'React Native: clone a string' | '348.44 ± 0.08%' | '331.00 ± 1.00' | '2927181 ± 0.04%' | '3021148 ± 9155' | 2869970 |
| 1 | 'ungap: clone a string' | '2037.4 ± 11.17%' | '1592.0 ± 50.00' | '617833 ± 0.09%' | '628141 ± 19947' | 490832 |
| 2 | 'React Native: clone a basic array' | '1460.2 ± 8.39%' | '1282.0 ± 20.00' | '775137 ± 0.42%' | '780031 ± 12362' | 684824 |
| 3 | 'ungap: clone a basic array' | '5112.8 ± 0.81%' | '4718.0 ± 111.00' | '205586 ± 0.08%' | '211954 ± 5107' | 195589 |
| 4 | 'React Native: clone a basic object' | '1373.8 ± 8.58%' | '1152.0 ± 20.00' | '842837 ± 0.46%' | '868056 ± 15337' | 727910 |
| 5 | 'ungap: clone a basic object' | '8853.2 ± 0.76%' | '8253.0 ± 141.00' | '117562 ± 0.05%' | '121168 ± 2106' | 112954 |
| 6 | 'React Native: clone a complex object' | '3539.4 ± 0.55%' | '3456.0 ± 50.00' | '288368 ± 0.02%' | '289352 ± 4248' | 282537 |
| 7 | 'ungap: clone a complex object' | '21498 ± 0.72%' | '20080 ± 301.00' | '48208 ± 0.09%' | '49801 ± 755' | 46516 |
The benchmark shows no material regression in the existing implementation and React Native remains faster than ungap/structured-clone across all scenarios.
Changelog:
[General][Added] - Add ArrayBuffer, DataView, typed array, boxed BigInt, and Error subclass support to structuredClone
Differential Revision: D1221566291 parent d194d8b commit 2d237d0
6 files changed
Lines changed: 354 additions & 50 deletions
File tree
- flow-typed/npm
- packages/react-native/src/private/webapis/structuredClone
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
Lines changed: 17 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
39 | 46 | | |
40 | 47 | | |
41 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
42 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
43 | 56 | | |
Lines changed: 106 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
102 | 109 | | |
103 | 110 | | |
104 | 111 | | |
| |||
223 | 230 | | |
224 | 231 | | |
225 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
226 | 285 | | |
227 | 286 | | |
228 | 287 | | |
| |||
261 | 320 | | |
262 | 321 | | |
263 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 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 | + | |
264 | 370 | | |
265 | 371 | | |
266 | 372 | | |
| |||
0 commit comments