Repository navigation
Compare layout-affecting attributes in text measurement cache keys - #60457
Merged
Merged
Conversation
Two Fabric paragraphs with the same source text can reuse a measurement even when they lay out differently. On iOS, an uppercase paragraph can reuse the lowercase paragraph's width and clip. On Android, `onTextLayout` can report the lowercase line while the view draws uppercase text. Compare `textTransform`, `baseWritingDirection`, `lineBreakStrategy`, `lineBreakMode`, `layoutDirection`, and `textEffects` in both cache keys. These attributes can change the measured size, line frames, line text, or inline attachment positions. Keys that differ only in these fields share a hash and compare unequal, so each measurement gets a separate entry. The oldest omission dates to the original size cache in 0.62. The line cache reused the same comparison when it shipped in 0.76. Passed the Fantom ReactCommon text layout tests and manual RNTester checks on iOS 27.0 and Android 16. Each row of the table-driven regression fails for both keys when its comparison is removed. The benchmark measures equality for one- and four-fragment keys on Apple silicon.
ide
force-pushed
the
@ide/text-measure-cache-key
branch
from
December 2, 2026 09:13
92f05b0 to
239b24a
Compare
ide
marked this pull request as ready for review
December 2, 2026 10:44
javache
approved these changes
Dec 2, 2026
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D135611163. |
christophpurrer
approved these changes
Dec 2, 2026
christophpurrer
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Collaborator
|
This pull request was successfully merged by @ide in e1be1bf When will my fix make it into a release? | How to file a pick request? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Two Fabric paragraphs with the same source text can reuse a measurement even when they lay out differently. On iOS, the second paragraph below can reuse the first paragraph's width of 165.7 pt, clipping the uppercase line. With the fix, the view measures 181.3 pt on the iPhone 18 Pro simulator. The screenshots show the larger RNTester fixture.
Both cache keys now distinguish the six omitted fragment attributes
textTransform,baseWritingDirection,lineBreakStrategy,lineBreakMode,layoutDirection, andtextEffects. TextKit uses the transform, direction and paragraph breaking fields, which can change the size, line frames, line text, or inline attachment positions. Android measures the transformed string, uses the layout direction for alignment and permits custom text effect spans that change font metrics. Android's default prepared-layout path bypasses the size cache. The prepared key already compares the three Android fields. Fabric still calls the line cache foronTextLayoutand baseline calculation.The oldest omission dates to the original size cache in 0.62. The line cache reused the same comparison when it shipped in 0.76.
Keys that differ only in these fields share a hash and compare unequal, so each measurement gets a separate entry. The tests cover these six fields; they would not catch a field added to
TextAttributeslater and left out of the keys, which would take a check over the struct's declarations.This change leaves two existing key defects alone: Android measures with the paragraph's base text attributes, which neither key includes, and the keys compare some floats with an epsilon but hash their exact values.
Changelog:
[GENERAL] [FIXED] - Avoid reusing Fabric text measurements across different transforms, directions, wrapping options, or Android text effects.
Test Plan:
Passed the Fantom ReactCommon text layout tests, covering equality for both cache keys, the layout hash and pixel-grid rounding. All six rows of the table-driven regression failed on
main. Removing one comparison at a time made only its corresponding row fail for both keys../gradlew :private:react-native-fantom:configureFantomTester --console=plain --max-workers=6 cmake --build private/react-native-fantom/build/tester --target react_renderer_textlayoutmanager_tests -j 6 ctest --test-dir private/react-native-fantom/build/tester/react-common-tests \ -R '^react/renderer/textlayoutmanager/tests/' --output-on-failurePassed a manual RNTester check on an iPhone 18 Pro with iOS 27.0. I used the same local screen in both builds and displayed
onLayoutandonTextLayoutvalues alongside the text. The uppercase view gets enough width for both words, andhangul-wordgets enough height for the third word. Two separately mounted multiline inputs verify that the character-wrapped input gets the height of its three lines. The inline attachment moves into the gap in the RTL writing-direction sample, and the right-aligneddirectionsample reports its own line x coordinate.xcodebuild -workspace packages/rn-tester/RNTesterPods.xcworkspace -scheme RNTester \ -configuration Debug -destination 'generic/platform=iOS Simulator' \ -derivedDataPath /private/tmp/rn-measure-cache-derived \ -jobs 6 ARCHS=arm64 ONLY_ACTIVE_ARCH=YES CODE_SIGNING_ALLOWED=NO buildPassed a manual RNTester check on an Android 16 arm64 emulator. The local screen pairs each fixed-size sample with a matching size, source string and font style. The effect sample uses a local
CacheProbeScalefactory that returns aScaleXSpan(1.6f)implementingTextEffectSpan. At the same view sizes,onTextLayoutreported the uppercase string, the scaled line width, and the right-aligned line's x coordinate.The layout hash uses the same code as
main. I measured equality on an Apple silicon Mac (Apple M6) with independent, equal keys whose fragments have no attachments or text effects. Apple Clang compiled the benchmark,AttributedString.cpp, andParagraphAttributes.cppat-O3. The table reports median retired instructions per comparison, including loop overhead, from five repetitions of 10 million comparisons after warming each executable.TextMeasureCacheKeyTextMeasureCacheKeyLineMeasureCacheKeyLineMeasureCacheKey