Repository navigation
Commit 2f470ce
Index MutationObserver child matching for wide lists (#60269)
Summary:
Pull Request resolved: #60269
## Context
When observed child vectors differ, MutationObserver searches the complete opposite list for every old and new child. After the shared-vector fast path, this remains quadratic work for appends, reorders and changes to one descendant of a wide observed node.
## Changes
- Index new child families when both lists contain at least 16 children, reducing matching to expected linear time with temporary storage proportional to the new list. Keep the original linear searches for smaller lists.
- Preserve the first matching new revision for each family, old-child traversal/removal order, new-child addition order, descendant-before-parent records and per-observer deduplication. Matches are not consumed, so repeated-family membership semantics remain unchanged.
- Extend the existing public-API regression suite with mixed reorder/descendant/addition/removal cases at widths 15, 16 and 32, using Fantom's default development mode.
## Benchmark results
Optimized native/JS code and Hermes bytecode, with MutationObserver enabled. These comparative measurements were collected at the preceding stable snapshot with the same observer implementations and benchmark fixtures: milliseconds of end-to-end update CPU time, aggregated as the median of three process runs' p50 values. Setup, reset renders, assertions and cleanup are outside the measured interval; reconciliation, observation, layout/mount work, record conversion and callback delivery are included.
The parent already includes the shared-vector fast path. Reductions below compare indexed matching with that parent.
| Workload | Children | Observers | Baseline (ms) | Parent: fast path (ms) | With indexed matching (ms) | Observed reduction vs. parent |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| Append one child | 1,024 | 1 | 6.322 | 7.829 | 4.850 | 38.0% |
| Add a grandchild in the last retained child | 1,024 | 1 | 6.271 | 6.623 | 4.883 | 26.3% |
| Reverse retained children | 1,024 | 1 | 8.716 | 9.674 | 8.032 | 17.0% |
| Replace all children | 1,024 | 1 | 30.210 | 32.900 | 29.119 | 11.5% |
Relative to baseline, the complete stack reduced observed append latency by 23.3% and descendant-update latency by 22.1% at width 1,024. Property-only gains belong to the preceding fast path, not this index.
All 47 scenarios passed in each of three timing runs per variant. Each scenario used at least 100 measured iterations, at least 250 ms measured execution, and 10 warmup iterations. These are synthetic measurements from one Linux worker, not isolated observer timings or device/app latency guarantees. Individual runs and unobserved controls varied; percentages are observed ratios of aggregate medians, not causal estimates or guaranteed speedups.
The unobserved width-1,024 append control measured 4.094 / 4.431 / 3.990 ms across baseline / fast-path / indexed phases; the descendant control measured 3.908 / 4.268 / 4.056 ms. Controls are not perfectly stable, so the raw percentages should not be interpreted as isolated native speedups. The 16-child cutoff remains conservative rather than tuned.
Changelog:
[General][Changed] - Reduce `MutationObserver` child matching overhead for wide observed lists
Reviewed By: javache
Differential Revision: D1342426571 parent fa3f4f2 commit 2f470ce
2 files changed
Lines changed: 133 additions & 5 deletions
File tree
- packages/react-native
- ReactCommon/react/renderer/observers/mutation
- src/private/webapis/mutationobserver/__tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
153 | 180 | | |
154 | 181 | | |
155 | 182 | | |
156 | 183 | | |
157 | | - | |
158 | | - | |
| 184 | + | |
| 185 | + | |
159 | 186 | | |
160 | 187 | | |
161 | 188 | | |
| |||
171 | 198 | | |
172 | 199 | | |
173 | 200 | | |
174 | | - | |
175 | | - | |
176 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
177 | 206 | | |
178 | 207 | | |
179 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
406 | 406 | | |
407 | 407 | | |
408 | 408 | | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
409 | 508 | | |
410 | 509 | | |
411 | 510 | | |
| |||
0 commit comments