Skip to content

Index MutationObserver child matching for wide lists (#60269) - #60269

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
rubennorte:export-D134242657
Nov 26, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
rubennorte:export-D134242657

Conversation

@rubennorte

@rubennorte rubennorte commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary:

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: D134242657

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 24, 2026
@meta-codesync

meta-codesync Bot commented Nov 24, 2026

Copy link
Copy Markdown

@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D134242657.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Visual regression

No visual differences at f73195771ac0.

rubennorte added a commit to rubennorte/react-native that referenced this pull request Nov 26, 2026
Summary:

## 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 are fresh measurements after rebasing: 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

Differential Revision: D134242657
@meta-codesync meta-codesync Bot changed the title Index MutationObserver child matching for wide lists Index MutationObserver child matching for wide lists (#60269) Nov 26, 2026
rubennorte added a commit to rubennorte/react-native that referenced this pull request Nov 26, 2026
Summary:

## 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 are fresh measurements after rebasing: 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

Differential Revision: D134242657
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 26, 2026

@javache javache left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

rubennorte added a commit to rubennorte/react-native that referenced this pull request Nov 26, 2026
Summary:

## 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 are fresh measurements after rebasing: 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: D134242657
rubennorte added a commit to rubennorte/react-native that referenced this pull request Nov 26, 2026
Summary:

## 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: D134242657
rubennorte added a commit to rubennorte/react-native that referenced this pull request Nov 26, 2026
Summary:
Pull Request resolved: react#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: D134242657
Summary:
Pull Request resolved: react#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: D134242657
@cipolleschi
cipolleschi enabled auto-merge (squash) November 26, 2026 15:37
@meta-codesync
meta-codesync Bot merged commit 9c71929 into react:main Nov 26, 2026
15 checks passed
@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 26, 2026
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @rubennorte in 9c71929

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants