Repository navigation
Skip MutationObserver diffing for shared child vectors (#60268) - #60268
Merged
Merged
Conversation
|
@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D134249269. |
Visual regressionNo visual differences at |
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Nov 26, 2026
Summary: ## Context Cloning a parent for a property-only update can leave its child-vector object unchanged. MutationObserver currently copies both vectors and compares their child families anyway, creating allocation/reference-counting work and quadratic searches even though none of the children changed. ## Changes Borrow the child vectors by const reference and return early when the vector objects are identical. Compare vector-object addresses, not their data pointers. This preserves deep-observation behavior: changes to a descendant require a different child revision along the path, so identical child-vector storage cannot hide a descendant mutation. ## 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. | Workload | Children | Observers | Baseline (ms) | Shared-vector fast path (ms) | Observed reduction | | --- | ---: | ---: | ---: | ---: | ---: | | Parent props only, deep observation | 1,024 | 1 | 3.846 | 2.076 | 46.0% | | Parent props only, deep observation | 256 | 10 | 1.843 | 0.519 | 71.9% | 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. This fast path only skips child matching when child-vector storage is shared. No append benefit is claimed: the width-1,024 fast-path-only append case measured 6.322 to 7.829 ms, while its unobserved control also varied (phase medians 4.094 to 4.431 ms; fast-phase run p50s 4.101, 5.189 and 4.431 ms). The observed slowdown is not isolated as a causal effect of this change. Changelog: [General][Changed] - Reduce `MutationObserver` overhead for commits with unchanged child vectors Differential Revision: D134249269
rubennorte
force-pushed
the
export-D134249269
branch
from
November 26, 2026 11:28
a43c678 to
fa957da
Compare
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Nov 26, 2026
Summary: ## Context Cloning a parent for a property-only update can leave its child-vector object unchanged. MutationObserver currently copies both vectors and compares their child families anyway, creating allocation/reference-counting work and quadratic searches even though none of the children changed. ## Changes Borrow the child vectors by const reference and return early when the vector objects are identical. Compare vector-object addresses, not their data pointers. This preserves deep-observation behavior: changes to a descendant require a different child revision along the path, so identical child-vector storage cannot hide a descendant mutation. ## 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. | Workload | Children | Observers | Baseline (ms) | Shared-vector fast path (ms) | Observed reduction | | --- | ---: | ---: | ---: | ---: | ---: | | Parent props only, deep observation | 1,024 | 1 | 3.846 | 2.076 | 46.0% | | Parent props only, deep observation | 256 | 10 | 1.843 | 0.519 | 71.9% | 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. This fast path only skips child matching when child-vector storage is shared. No append benefit is claimed: the width-1,024 fast-path-only append case measured 6.322 to 7.829 ms, while its unobserved control also varied (phase medians 4.094 to 4.431 ms; fast-phase run p50s 4.101, 5.189 and 4.431 ms). The observed slowdown is not isolated as a causal effect of this change. Changelog: [General][Changed] - Reduce `MutationObserver` overhead for commits with unchanged child vectors Differential Revision: D134249269
rubennorte
force-pushed
the
export-D134249269
branch
from
November 26, 2026 13:48
fa957da to
c0ce2ab
Compare
javache
approved these changes
Nov 26, 2026
javache
left a comment
Contributor
There was a problem hiding this comment.
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 Cloning a parent for a property-only update can leave its child-vector object unchanged. MutationObserver currently copies both vectors and compares their child families anyway, creating allocation/reference-counting work and quadratic searches even though none of the children changed. ## Changes Borrow the child vectors by const reference and return early when the vector objects are identical. Compare vector-object addresses, not their data pointers. This preserves deep-observation behavior: changes to a descendant require a different child revision along the path, so identical child-vector storage cannot hide a descendant mutation. ## 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. | Workload | Children | Observers | Baseline (ms) | Shared-vector fast path (ms) | Observed reduction | | --- | ---: | ---: | ---: | ---: | ---: | | Parent props only, deep observation | 1,024 | 1 | 3.846 | 2.076 | 46.0% | | Parent props only, deep observation | 256 | 10 | 1.843 | 0.519 | 71.9% | 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. This fast path only skips child matching when child-vector storage is shared. No append benefit is claimed: the width-1,024 fast-path-only append case measured 6.322 to 7.829 ms, while its unobserved control also varied (phase medians 4.094 to 4.431 ms; fast-phase run p50s 4.101, 5.189 and 4.431 ms). The observed slowdown is not isolated as a causal effect of this change. Changelog: [General][Changed] - Reduce `MutationObserver` overhead for commits with unchanged child vectors Reviewed By: javache Differential Revision: D134249269
rubennorte
force-pushed
the
export-D134249269
branch
from
November 26, 2026 14:22
c0ce2ab to
f03db07
Compare
Summary: ## Context MutationObserver observation adds work to React commits even when a commit does not change the observed child list. Establish public-API benchmarks before changing the native implementation so that each optimization can be measured independently against the same workloads. ## Changes Add 47 Fantom scenarios covering widths 2, 32, 256 and 1,024; parent props, append, full replacement, reorder and descendant changes; shallow/deep observation; unobserved controls; and multiple observers. Setup, reset renders, assertions and cleanup are outside the measured interval. Each measured update includes reconciliation, observation, layout/mount processing, record conversion and callback delivery. ## Baseline 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. | Workload | Children | Observers | Baseline CPU time (ms) | | --- | ---: | ---: | ---: | | Parent props only, deep observation | 1,024 | 1 | 3.846 | | Append one child | 1,024 | 1 | 6.322 | | Add a grandchild in the last retained child | 1,024 | 1 | 6.271 | | Reverse retained children | 1,024 | 1 | 8.716 | | Replace all children | 1,024 | 1 | 30.210 | | Parent props only, deep observation | 256 | 10 | 1.843 | 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 following optimizations use this benchmark unchanged. Changelog: [Internal] Reviewed By: javache Differential Revision: D134249229
Summary: ## Context Cloning a parent for a property-only update can leave its child-vector object unchanged. MutationObserver currently copies both vectors and compares their child families anyway, creating allocation/reference-counting work and quadratic searches even though none of the children changed. ## Changes Borrow the child vectors by const reference and return early when the vector objects are identical. Compare vector-object addresses, not their data pointers. This preserves deep-observation behavior: changes to a descendant require a different child revision along the path, so identical child-vector storage cannot hide a descendant mutation. ## 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. | Workload | Children | Observers | Baseline (ms) | Shared-vector fast path (ms) | Observed reduction | | --- | ---: | ---: | ---: | ---: | ---: | | Parent props only, deep observation | 1,024 | 1 | 3.846 | 2.076 | 46.0% | | Parent props only, deep observation | 256 | 10 | 1.843 | 0.519 | 71.9% | 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. This fast path only skips child matching when child-vector storage is shared. No append benefit is claimed: the width-1,024 fast-path-only append case measured 6.322 to 7.829 ms, while its unobserved control also varied (phase medians 4.094 to 4.431 ms; fast-phase run p50s 4.101, 5.189 and 4.431 ms). The observed slowdown is not isolated as a causal effect of this change. Changelog: [General][Changed] - Reduce `MutationObserver` overhead for commits with unchanged child vectors Reviewed By: javache Differential Revision: D134249269
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Nov 26, 2026
Summary: ## Context Cloning a parent for a property-only update can leave its child-vector object unchanged. MutationObserver currently copies both vectors and compares their child families anyway, creating allocation/reference-counting work and quadratic searches even though none of the children changed. ## Changes Borrow the child vectors by const reference and return early when the vector objects are identical. Compare vector-object addresses, not their data pointers. This preserves deep-observation behavior: changes to a descendant require a different child revision along the path, so identical child-vector storage cannot hide a descendant mutation. ## 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. | Workload | Children | Observers | Baseline (ms) | Shared-vector fast path (ms) | Observed reduction | | --- | ---: | ---: | ---: | ---: | ---: | | Parent props only, deep observation | 1,024 | 1 | 3.846 | 2.076 | 46.0% | | Parent props only, deep observation | 256 | 10 | 1.843 | 0.519 | 71.9% | 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. This fast path only skips child matching when child-vector storage is shared. No append benefit is claimed: the width-1,024 fast-path-only append case measured 6.322 to 7.829 ms, while its unobserved control also varied (phase medians 4.094 to 4.431 ms; fast-phase run p50s 4.101, 5.189 and 4.431 ms). The observed slowdown is not isolated as a causal effect of this change. Changelog: [General][Changed] - Reduce `MutationObserver` overhead for commits with unchanged child vectors Reviewed By: javache Differential Revision: D134249269
rubennorte
force-pushed
the
export-D134249269
branch
from
November 26, 2026 14:22
f03db07 to
c327037
Compare
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Nov 26, 2026
Summary: Pull Request resolved: react#60268 ## Context Cloning a parent for a property-only update can leave its child-vector object unchanged. MutationObserver currently copies both vectors and compares their child families anyway, creating allocation/reference-counting work and quadratic searches even though none of the children changed. ## Changes Borrow the child vectors by const reference and return early when the vector objects are identical. Compare vector-object addresses, not their data pointers. This preserves deep-observation behavior: changes to a descendant require a different child revision along the path, so identical child-vector storage cannot hide a descendant mutation. ## 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. | Workload | Children | Observers | Baseline (ms) | Shared-vector fast path (ms) | Observed reduction | | --- | ---: | ---: | ---: | ---: | ---: | | Parent props only, deep observation | 1,024 | 1 | 3.846 | 2.076 | 46.0% | | Parent props only, deep observation | 256 | 10 | 1.843 | 0.519 | 71.9% | 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. This fast path only skips child matching when child-vector storage is shared. No append benefit is claimed: the width-1,024 fast-path-only append case measured 6.322 to 7.829 ms, while its unobserved control also varied (phase medians 4.094 to 4.431 ms; fast-phase run p50s 4.101, 5.189 and 4.431 ms). The observed slowdown is not isolated as a causal effect of this change. Changelog: [General][Changed] - Reduce `MutationObserver` overhead for commits with unchanged child vectors Reviewed By: javache Differential Revision: D134249269
Collaborator
|
This pull request was successfully merged by @rubennorte in 3153433 When will my fix make it into a release? | How to file a pick request? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Context
Cloning a parent for a property-only update can leave its child-vector object unchanged. MutationObserver currently copies both vectors and compares their child families anyway, creating allocation/reference-counting work and quadratic searches even though none of the children changed.
Changes
Borrow the child vectors by const reference and return early when the vector objects are identical. Compare vector-object addresses, not their data pointers. This preserves deep-observation behavior: changes to a descendant require a different child revision along the path, so identical child-vector storage cannot hide a descendant mutation.
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.
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.
This fast path only skips child matching when child-vector storage is shared. No append benefit is claimed: the width-1,024 fast-path-only append case measured 6.322 to 7.829 ms, while its unobserved control also varied (phase medians 4.094 to 4.431 ms; fast-phase run p50s 4.101, 5.189 and 4.431 ms). The observed slowdown is not isolated as a causal effect of this change.
Changelog:
[General][Changed] - Reduce
MutationObserveroverhead for commits with unchanged child vectorsReviewed By: javache
Differential Revision: D134249269