Skip to content

Simplify Fabric Differentiator mutation calculation (#57153)#57153

Open
sammy-SC wants to merge 4 commits into
react:mainfrom
sammy-SC:export-D108027813
Open

Simplify Fabric Differentiator mutation calculation (#57153)#57153
sammy-SC wants to merge 4 commits into
react:mainfrom
sammy-SC:export-D108027813

Conversation

@sammy-SC

@sammy-SC sammy-SC commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary:

calculateShadowViewMutationsFlattener (CCN 73) and calculateShadowViewMutations (CCN 45) are the core of the Fabric tree differ and were the two most complex functions in the mounting library. This is a pure, behavior-preserving refactor: cohesive blocks are extracted into file-local static helpers (remove/insert-on-(un)flatten, matched-grandchildren update, opposite/normal reparent handling, and the greedy diff stages), turning both functions into flat sequences of helper calls. Traversal order and the exact sequence of emitted mutations are preserved. Only the .cpp is touched; no header or public API change.

Changelog: [Internal]

Differential Revision: D108027813

@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 Jun 9, 2026
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Jun 9, 2026
sammy-SC added 4 commits June 9, 2026 09:11
Summary:

`BaseTextProps::appendTextAttributesProps` builds a `folly::dynamic` diff of ~29 text attributes through a long flat sequence of per-attribute `if (changed) result[key] = ...` blocks, many with an embedded `has_value() ? convert(...) : nullptr` ternary. That gave the function a cyclomatic complexity (CCN) of 47, well into the "complex, hard to test" range.

This is a pure, behavior-preserving refactor. The four recurring compare-and-assign shapes — plain `!=`, `floatEquality`, optional-with-converter, and color dereference — are pulled into small file-local `static` helpers, and the function body becomes a flat list of helper calls in the exact same order, with the exact same keys, conversions, and values. The serialized output (including `folly::dynamic` insertion order) is identical. Only the `.cpp` is touched; there are no public header or API changes.

Changelog: [Internal]

Differential Revision: D108027815
Summary:

`AndroidTextInputProps::getDiffProps` computes a `folly::dynamic` prop diff through ~57 sequential per-prop `if (field != oldProps->field) result[key] = ...` blocks (plus a nested `has_value()` branch for `textAlignVertical` and an optional ternary for `acceptDragAndDropTypes`), giving the function a cyclomatic complexity (CCN) of 63 — past the landing threshold.

This is a pure, behavior-preserving refactor. The recurring compare-and-assign shapes — plain `!=`, color dereference, `floatEquality`, direct `toString`/`toDynamic` conversion, and optional-with-converter — are pulled into small file-local `static` helpers, and the body becomes a flat list of helper calls in the exact same order, with the same keys, comparisons (`!=` vs `floatEquality`), conversions, and values. The serialized output (including `folly::dynamic` insertion order, so the duplicate `numberOfLines`/`includeFontPadding` keys still resolve identically) is unchanged. Only the `.cpp` is touched; there are no public header or API changes.

Changelog: [Internal]

Differential Revision: D108027818
Summary:

`HostPlatformViewProps::getDiffProps` computes a `folly::dynamic` prop diff for Android with the highest complexity in the file: ~60 sequential per-prop `if (field != oldProps->field) result[key] = ...` guards plus inline `switch`es (`outlineStyle`, `backfaceVisibility`), a 28-call events block, a transform loop, and several accessibility object/array builders, for a cyclomatic complexity (CCN) of 87.

This is a pure, behavior-preserving refactor. The recurring compare-and-assign shapes — plain `!=`, color dereference, direct `toString`/`toDynamic` conversion, and optional-with-converter — are pulled into small file-local `static` helpers, and the genuinely branching blocks (the two enum `switch`es, `overflow`/`scroll`, the events block, the transform loop, and the accessibility state/labelledBy/order/value/actions builders) are each moved verbatim into a named helper. Every prop keeps its explicit key/value/conversion on one line and in the same order, so the serialized `folly::dynamic` (keys, values, insertion order) is identical. The `// Borders` block is left inline unchanged. Only the `.cpp` is touched; there are no public header or API changes.

Changelog: [Internal]

Differential Revision: D108027816
Summary:

`calculateShadowViewMutationsFlattener` (CCN 73) and `calculateShadowViewMutations` (CCN 45) are the core of the Fabric tree differ and were the two most complex functions in the mounting library. This is a pure, behavior-preserving refactor: cohesive blocks are extracted into file-local `static` helpers (remove/insert-on-(un)flatten, matched-grandchildren update, opposite/normal reparent handling, and the greedy diff stages), turning both functions into flat sequences of helper calls. Traversal order and the exact sequence of emitted mutations are preserved. Only the `.cpp` is touched; no header or public API change.

Changelog: [Internal]

Differential Revision: D108027813
@sammy-SC sammy-SC force-pushed the export-D108027813 branch from bcb055c to e656c0b Compare June 9, 2026 16:12
@meta-codesync meta-codesync Bot changed the title Simplify Fabric Differentiator mutation calculation Simplify Fabric Differentiator mutation calculation (#57153) Jun 9, 2026
@meta-codesync

meta-codesync Bot commented Jun 9, 2026

Copy link
Copy Markdown

@sammy-SC has exported this pull request. If you are a Meta employee, you can view the originating Diff in D108027813.

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. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant