Skip to content

Fix per-node memory regression caused by Grid styles (#58311) - #58311

Closed
javache wants to merge 1 commit into
react:mainfrom
javache:export-D118628661
Closed

Fix per-node memory regression caused by Grid styles (#58311)#58311
javache wants to merge 1 commit into
react:mainfrom
javache:export-D118628661

Conversation

@javache

@javache javache commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary:

Why

Currently, grid style properties are stored in yoga style (gridTemplateRows_, gridAutoColumns_ etc). These properties increase the size of style object from 152 bytes to 280 bytes (84% increase). The cost is added even when a node is not a grid container or a grid item.

How

Move grid style properties behind a pointer that is lazily allocated, on the first grid property set. A node that doesn't use grid only adds the cost of this pointer (8 bytes). So style now costs 160 bytes (5% increase). The public API remains unchanged.

Tests

A test is added to catch the style size regression and tests/GridStyleTest.cpp includes additional cases to assert unset style, copy and move behaviour.

X-link: react/yoga#2018

Reviewed By: rubennorte

Differential Revision: D118628661

Pulled By: javache

@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 Sep 3, 2026
@meta-codesync

meta-codesync Bot commented Sep 3, 2026

Copy link
Copy Markdown

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

Summary:

# Why

Currently, grid style properties are stored in yoga style (`gridTemplateRows_`, `gridAutoColumns_` etc). These properties increase the size of style object from `152` bytes to `280` bytes (84% increase). The cost is added even when a node is not a grid container or a grid item.

# How

Move grid style properties behind a pointer that is lazily allocated, on the first grid property set. A node that doesn't use grid only adds the cost of this pointer (8 bytes). So style now costs 160 bytes (5% increase). The public API remains unchanged.

# Tests

A test is added to catch the style size regression and `tests/GridStyleTest.cpp` includes additional cases to assert unset style, copy and move behaviour.

X-link: react/yoga#2018

Reviewed By: rubennorte

Differential Revision: D118628661

Pulled By: javache
@meta-codesync meta-codesync Bot changed the title Fix per-node memory regression caused by Grid styles Fix per-node memory regression caused by Grid styles (#58311) Sep 4, 2026
meta-codesync Bot pushed a commit to react/yoga that referenced this pull request Sep 4, 2026
Summary:
X-link: react/react-native#58311

# Why

Currently, grid style properties are stored in yoga style (`gridTemplateRows_`, `gridAutoColumns_` etc). These properties increase the size of style object from `152` bytes to `280` bytes (84% increase). The cost is added even when a node is not a grid container or a grid item.

# How

Move grid style properties behind a pointer that is lazily allocated, on the first grid property set. A node that doesn't use grid only adds the cost of this pointer (8 bytes). So style now costs 160 bytes (5% increase). The public API remains unchanged.

# Tests

A test is added to catch the style size regression and `tests/GridStyleTest.cpp` includes additional cases to assert unset style, copy and move behaviour.

Changelog: [Internal]

Pull Request resolved: #2018

Reviewed By: rubennorte

Differential Revision: D118628661

Pulled By: javache

fbshipit-source-id: 185370e93bcf5b277b48c436ba3d06dada5a66fe
@meta-codesync meta-codesync Bot closed this in 63d118a Sep 4, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Sep 4, 2026
@meta-codesync

meta-codesync Bot commented Sep 4, 2026

Copy link
Copy Markdown

@javache merged this pull request in 63d118a.

@javache
javache deleted the export-D118628661 branch September 4, 2026 20:11
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-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants