Skip to content

Avoid redundant dynamic_pointer_cast in YogaLayoutableShadowNode clone (#57019)#57019

Open
javache wants to merge 1 commit into
facebook:mainfrom
javache:export-D106287171
Open

Avoid redundant dynamic_pointer_cast in YogaLayoutableShadowNode clone (#57019)#57019
javache wants to merge 1 commit into
facebook:mainfrom
javache:export-D106287171

Conversation

@javache
Copy link
Copy Markdown
Member

@javache javache commented Jun 1, 2026

Summary:

The clone constructor of YogaLayoutableShadowNode rebuilt the
internal yogaLayoutableChildren_ vector on every clone by
walking every child with dynamic_pointer_cast. When the cloned
node inherits its children list from the source (!fragment.children)
the result is identical to the source's vector, so copy it directly
instead — no RTTI required.

Also reserve() the vector to its upper bound at the top of
updateYogaChildren() so the rebuild on the new-children path no
longer reallocates as it grows.

Both changes are pure CPU-time optimizations on a hot path that
shows up heavily in animation-driven tree clones; behaviour is
unchanged.

Changelog:
[Internal]

Reviewed By: christophpurrer, lenaic

Differential Revision: D106287171

@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 1, 2026
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Jun 1, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Jun 1, 2026

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

facebook#57019)

Summary:

The clone constructor of `YogaLayoutableShadowNode` rebuilt the
internal `yogaLayoutableChildren_` vector on every clone by
walking every child with `dynamic_pointer_cast`. When the cloned
node inherits its children list from the source (`!fragment.children`)
the result is identical to the source's vector, so copy it directly
instead — no RTTI required.

Also `reserve()` the vector to its upper bound at the top of
`updateYogaChildren()` so the rebuild on the new-children path no
longer reallocates as it grows.

Both changes are pure CPU-time optimizations on a hot path that
shows up heavily in animation-driven tree clones; behaviour is
unchanged.

Changelog:
[Internal]

Reviewed By: christophpurrer, lenaic

Differential Revision: D106287171
@meta-codesync meta-codesync Bot changed the title Avoid redundant dynamic_pointer_cast in YogaLayoutableShadowNode clone Avoid redundant dynamic_pointer_cast in YogaLayoutableShadowNode clone (#57019) Jun 2, 2026
@javache javache force-pushed the export-D106287171 branch from 5be76c0 to c96be7d Compare June 2, 2026 12:24
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. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant