Skip to content

Use exact float equality in text measurement cache keys - #60464

Merged
Abbondanzo merged 1 commit into
react:mainfrom
expo:@ide/text-cache-exact-floats
Dec 4, 2026
Merged

Abbondanzo merged 1 commit into
react:mainfrom
expo:@ide/text-cache-exact-floats

Conversation

@ide

@ide ide commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

The Fabric text keys compare font sizes, paragraph font limits and pixel scales within an epsilon. The hash uses the original values. With libc++, neighboring values can compare equal and still occupy separate entries. An infinite font limit also exposes an eviction failure. The key compares unequal to itself, so the LRU drops its list entry while the map retains it.

Compare text attribute floats, paragraph font limits and point scale exactly in the cache keys. Keep neighboring finite inputs distinct, reuse identical infinities and treat NaNs as unset. Hash normalized integer encodings for those fields, including both coordinates of a present shadow offset.

Lookup and eviction for adjacent floats, NaNs and infinity

Changelog:

[INTERNAL] [FIXED] - Make Fabric text measurement cache equality agree with hashing.

Test Plan:

./gradlew :private:react-native-fantom:configureFantomTester --console=plain --max-workers=5
cmake --build private/react-native-fantom/build/tester \
  --target react_renderer_textlayoutmanager_tests react_renderer_attributedstring_tests -j 6
ctest --test-dir private/react-native-fantom/build/tester/react-common-tests \
  -R '^react/renderer/(textlayoutmanager|attributedstring)/tests/' --output-on-failure
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --rerun \
  --tests 'com.facebook.react.views.text.*' --console=plain --max-workers=4

The four float regressions fail on upstream and pass with the patch. They detect restoring epsilon equality, hashing raw NaNs or signed zeros, and comparing or hashing raw shadow coordinates. A fifth test checks that prepared keys compare lineBreakMode, which upstream already does. The C++ probe records cache reuse and map erasure during eviction.

Terminal output from the cache lookup and eviction probe

Apple Clang 21 -O3 on Apple M6. The table compares median retired instructions per equal-key comparison or hash on upstream/main at a174e2c726 and this branch. Each median uses three warmed runs with five repetitions per run. The size and line fixtures use the Fantom C++ types.

Key path Fragments Equality before → after Hash before → after
Size 1 550.05 → 541.06 370.04 → 370.04
Size 4 1741.12 → 1705.12 1108.08 → 1075.08
Lines 1 530.05 → 526.05 345.04 → 341.04
Lines 4 1721.13 → 1690.12 1083.09 → 1046.08
Android prepared 1 721.06 → 696.07 528.05 → 509.05
Android prepared 4 2428.21 → 2325.17 1731.12 → 1631.11
Android prepared with shadow 1 724.07 → 704.07 544.06 → 531.05
Android prepared with shadow 4 2440.19 → 2357.18 1795.14 → 1719.12

All key rows and all TextAttributesHashBenchmark.cpp fixtures match or improve on main within the observed per-fixture range. The optimized layout hash retires 171.03–249.04 instructions on main and 163.03–241.04 on this branch. The ordinary attribute hash uses the same implementation as main and retires 324.04–495.06 instructions on both.

@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 Dec 2, 2026
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 2, 2026
@ide
ide marked this pull request as ready for review December 2, 2026 12:20
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Dec 2, 2026
@ide
ide force-pushed the @ide/text-cache-exact-floats branch from 3c84cbb to 4ca5e79 Compare December 2, 2026 15:13
@ide
ide marked this pull request as draft December 2, 2026 15:42
@ide
ide force-pushed the @ide/text-cache-exact-floats branch 2 times, most recently from 83bcb1d to 7830ed5 Compare December 3, 2026 01:34
@ide
ide marked this pull request as ready for review December 3, 2026 03:07
@ide
ide force-pushed the @ide/text-cache-exact-floats branch from 7830ed5 to 0ecb311 Compare December 3, 2026 13:31
Text measurement keys can compare equal and hash differently for neighboring floats or for two representations of an unset value. An infinite paragraph font limit can leave an entry in the LRU map after eviction because the key compares unequal to itself.

Compare cache floats exactly and hash their canonical integer encodings, including both coordinates of a present shadow offset. Combine float pairs on 64-bit platforms with 32-bit floats and fold attribute optionals into one presence mask.

On Apple M6, the four-fragment size, line and prepared hashes retire 1108.08 → 1075.08, 1083.09 → 1046.08 and 1731.12 → 1631.11 instructions, respectively. The ordinary attribute hash fixtures match upstream within the measured noise.

The Fantom text layout and attributed string suites and Android text unit tests pass. The four float regressions fail on upstream and detect the corresponding mutations.

Signed-off-by: James Ide <ide@expo.dev>
@ide
ide force-pushed the @ide/text-cache-exact-floats branch from 0ecb311 to 3d228bf Compare December 4, 2026 20:14
@Abbondanzo
Abbondanzo merged commit 40b5378 into react:main Dec 4, 2026
101 of 104 checks passed
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 Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants