Skip to content

Skip repeated style lookups in min-content walks - #2219

Open
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/min-content-walk-lookups
Open

ide wants to merge 1 commit into
react:mainfrom
expo:@ide/min-content-walk-lookups

Conversation

@ide

@ide ide commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Why

With MinSizeUndefinedInsteadOfAuto cleared, Yoga can walk a flex item's subtree to compute its automatic minimum size. To measure a leaf's min-content height, the walk derives its content width from each enclosing box. It resolves some of the same style values more than once per box. CSS Flexbox §4.5

How

Pass each container's resolved direction to contentWidthUnderOwner. Resolve a measured leaf's direction again after the callback because the callback can change it. Subtract margins only when the owner width is defined. If the resulting width is undefined, use the resolved maximum width as the input to the bounds check.

Resolve stored width and height values directly with Style::resolvedDimension. Resolve a child's cross-axis size only when an aspect ratio can transfer that size to the measured axis.

Test Plan

cmake --build tests/build && tests/build/yogatests passes. One regression test checks that opposing percentage margins whose sum overflows to NaN still let a leaf measure at its max-width. Another changes the leaf's direction to RTL within its min-content callback and checks that its automatic minimum width includes the RTL padding.

Fuzz layouts match main for 200,000 varied trees and 200,000 nested trees with default configs and for 300,000 flat rows. They also match for 200,000 varied trees per config mode with MinSizeUndefinedInsteadOfAuto cleared, with all errata cleared, and with mixed node configs.

Callgrind counts instructions in one YGNodeCalculateLayout call. GCC first layouts use the CI harness. Clang first layouts and both compilers' relayouts use a harness that replays the same captures. "All errata" uses the captured React Native config. "No errata" clears every erratum. The first-layout table compares #2218 with this change.

Relayouts with no errata

Relayout Compiler 3a201ff47 Main baseline #2218 This change Change from #2218 Change from 3a201ff47
rendering-sample-mac, one text grows GCC 15.2 x86-64 246,928 333,330 256,769 236,553 −7.87% −4.20%
rendering-sample-mac, one text grows Clang 18.1 arm64 264,393 347,824 256,364 239,304 −6.65% −9.49%
profile-ios, then the root narrows by 20pt GCC 15.2 x86-64 1,162,027 1,268,056 1,101,596 1,098,279 −0.30% −5.49%
profile-ios, then the root narrows by 20pt Clang 18.1 arm64 1,313,623 1,365,936 1,149,762 1,147,321 −0.21% −12.66%
chat-mac, one text grows GCC 15.2 x86-64 1,099,172 1,110,516 987,547 983,130 −0.45% −10.56%
chat-mac, one text grows Clang 18.1 arm64 1,062,258 1,029,942 872,183 869,089 −0.35% −18.18%

The other relayouts change by −0.91% to +0.00% with GCC and −0.67% to +0.00% with Clang.

First layout

Capture Errata GCC 15.2 x86-64 Change Clang 18.1 arm64 Change
chat-mac all errata 42,238,101 → 42,238,384 +0.00% 43,685,141 → 43,685,141 +0.00%
chat-mac no errata 49,472,849 → 49,297,928 −0.35% 51,298,624 → 51,157,887 −0.27%
feed-android all errata 8,236,026 → 8,236,019 −0.00% 8,566,118 → 8,566,118 +0.00%
feed-android no errata 8,975,977 → 8,922,530 −0.60% 9,255,504 → 9,210,881 −0.48%
profile-ios all errata 1,627,904 → 1,627,883 −0.00% 1,698,555 → 1,698,555 +0.00%
profile-ios no errata 1,549,111 → 1,540,062 −0.58% 1,612,305 → 1,604,555 −0.48%
rendering-sample-mac all errata 749,944 → 749,944 +0.00% 764,552 → 764,552 +0.00%
rendering-sample-mac no errata 913,338 → 889,504 −2.61% 934,103 → 914,623 −2.09%

Changelog: [Internal]

@ide
ide force-pushed the @ide/min-content-walk-lookups branch 2 times, most recently from b8e7023 to 9429781 Compare December 4, 2026 01:42
@ide
ide marked this pull request as ready for review December 4, 2026 01:48
@ide
ide force-pushed the @ide/min-content-walk-lookups branch from 9429781 to a1791cd Compare December 4, 2026 11:33
Why
===

With `MinSizeUndefinedInsteadOfAuto` cleared, Yoga can walk a flex item's subtree to compute its automatic minimum size. To measure a leaf's min-content height, the walk derives its content width from each enclosing box. It resolves some of the same style values more than once per box. [CSS Flexbox §4.5](https://www.w3.org/TR/css-flexbox-1/#min-size-auto)

How
===

Pass each container's resolved direction to `contentWidthUnderOwner`. Resolve a measured leaf's direction again after the callback because the callback can change it. Subtract margins only when the owner width is defined. If the resulting width is undefined, use the resolved maximum width as the input to the bounds check.

Resolve stored width and height values directly with `Style::resolvedDimension`. Resolve a child's cross-axis size only when an aspect ratio can transfer that size to the measured axis.

Test Plan
===

`cmake --build tests/build && tests/build/yogatests` passes. One regression test checks that opposing percentage margins whose sum overflows to NaN still let a leaf measure at its `max-width`. Another changes the leaf's direction to RTL within its min-content callback and checks that its automatic minimum width includes the RTL padding.

Fuzz layouts match main for 200,000 varied trees and 200,000 nested trees with default configs and for 300,000 flat rows. They also match for 200,000 varied trees per config mode with `MinSizeUndefinedInsteadOfAuto` cleared, with all errata cleared, and with mixed node configs.

Callgrind counts instructions in one `YGNodeCalculateLayout` call. GCC first layouts use the CI harness. Clang first layouts and both compilers' relayouts use a harness that replays the same captures. "All errata" uses the captured React Native config. "No errata" clears every erratum. The first-layout table compares react#2218 with this change.

**Relayouts with no errata**

| Relayout | Compiler | `3a201ff47` | Main baseline | react#2218 | This change | Change from react#2218 | Change from `3a201ff47` |
| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: |
| rendering-sample-mac, one text grows | GCC 15.2 x86-64 | 246,928 | 333,330 | 256,769 | 236,553 | −7.87% | −4.20% |
| rendering-sample-mac, one text grows | Clang 18.1 arm64 | 264,393 | 347,824 | 256,364 | 239,304 | −6.65% | −9.49% |
| profile-ios, then the root narrows by 20pt | GCC 15.2 x86-64 | 1,162,027 | 1,268,056 | 1,101,596 | 1,098,279 | −0.30% | −5.49% |
| profile-ios, then the root narrows by 20pt | Clang 18.1 arm64 | 1,313,623 | 1,365,936 | 1,149,762 | 1,147,321 | −0.21% | −12.66% |
| chat-mac, one text grows | GCC 15.2 x86-64 | 1,099,172 | 1,110,516 | 987,547 | 983,130 | −0.45% | −10.56% |
| chat-mac, one text grows | Clang 18.1 arm64 | 1,062,258 | 1,029,942 | 872,183 | 869,089 | −0.35% | −18.18% |

The other relayouts change by −0.91% to +0.00% with GCC and −0.67% to +0.00% with Clang.

**First layout**

| Capture | Errata | GCC 15.2 x86-64 | Change | Clang 18.1 arm64 | Change |
| --- | --- | ---: | ---: | ---: | ---: |
| chat-mac | all errata | 42,238,101 → 42,238,384 | +0.00% | 43,685,141 → 43,685,141 | +0.00% |
| chat-mac | no errata | 49,472,849 → 49,297,928 | −0.35% | 51,298,624 → 51,157,887 | −0.27% |
| feed-android | all errata | 8,236,026 → 8,236,019 | −0.00% | 8,566,118 → 8,566,118 | +0.00% |
| feed-android | no errata | 8,975,977 → 8,922,530 | −0.60% | 9,255,504 → 9,210,881 | −0.48% |
| profile-ios | all errata | 1,627,904 → 1,627,883 | −0.00% | 1,698,555 → 1,698,555 | +0.00% |
| profile-ios | no errata | 1,549,111 → 1,540,062 | −0.58% | 1,612,305 → 1,604,555 | −0.48% |
| rendering-sample-mac | all errata | 749,944 → 749,944 | +0.00% | 764,552 → 764,552 | +0.00% |
| rendering-sample-mac | no errata | 913,338 → 889,504 | −2.61% | 934,103 → 914,623 | −2.09% |

Changelog: [Internal]

Signed-off-by: James Ide <ide@expo.dev>
@ide
ide force-pushed the @ide/min-content-walk-lookups branch from a1791cd to e55972b Compare December 5, 2026 16:45

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant