Repository navigation
Conversation
Visual regressionNo visual differences at |
Nested text can have identical fragments and different base paint. Android initializes the paint from the paragraph's base attributes, so onTextLayout can report the smaller paragraph's capHeight and xHeight for both paragraphs. Compare and hash the attributes that initialize Android's paint in the size, line and prepared-layout keys. Android opts into the base paint for the shared size and line keys so matching iOS fragments can still reuse their measurements. The Fantom text layout tests exercise the three keys and the shared keys without base paint. The Android text unit tests pass. RNTester reports distinct line metrics for identical inner text at the same width.
ide
force-pushed
the
@ide/android-text-cache-base-paint
branch
from
December 2, 2026 12:20
e49693f to
c4212c7
Compare
ide
marked this pull request as ready for review
December 2, 2026 13:45
ide
marked this pull request as draft
December 2, 2026 15:40
Contributor
Author
|
Closing without merging. Comparing and hashing the paragraph's base paint attributes in every Android text cache key costs 29–48% more instructions per lookup, which is too much for this case. This PR stays as a record of the defect: Android measures with the paragraph's base paint, which none of the size, line or prepared-layout keys include. Two paragraphs whose fragments match but whose outer font differs can therefore share a cached line measurement. In the example above, a 44 dp paragraph reports the 20 dp paragraph's |
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:
Fabric on Android initializes its measurement paint from the paragraph's base attributes. Those attributes can differ after nested text overrides them in every fragment. Two paragraphs with identical fragments and widths can then share a line measurement even though their paints produce different
capHeightandxHeightvalues.Include the base font and spacing inputs in the Android size, line and prepared-layout keys. The iOS size and line keys still reuse measurements when their fragments match. For empty iOS strings, the placeholder fragment already carries the base attributes.
Changelog:
[ANDROID] [FIXED] - Use the paragraph's base paint when caching Fabric text measurements.
Test Plan:
Built the Fantom tester target and ran its CTest suite.
./gradlew :private:react-native-fantom:configureFantomTester --console=plain --max-workers=5 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-failureThe C++ regressions cover every base paint field in the size, line and prepared keys. They detect missing base comparisons, missing hash contributions and applying the base to the shared iOS keys.
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --rerun \ --tests 'com.facebook.react.views.text.*' --console=plain --max-workers=4 ./gradlew :packages:rn-tester:android:app:assembleDebug \ -PreactNativeArchitectures=arm64-v8a --console=plain --max-workers=4In RNTester on Android 16, the first sample uses a 20 dp outer font at 280 dp width and primes the line cache. The second uses a 44 dp outer font at the same width. Both render 20 dp inner text. Separate-width samples expose each paragraph's metrics on a fresh key. The 44 dp sample at the shared width changes from 14.5 and 10.7 dp to 31.8 and 23.5 dp, matching the separate-width sample. RNTester exercises the Android line cache. The Fantom tests cover the size and prepared keys. Before capture · After capture.
Apple Clang
-O3, Apple M6. Median retired instructions per full key comparison or hash, over five warmed repetitions. The comparison uses two equal copies of each key. The benchmark uses the Fantom C++ build's types and enables the Android base-paint field for the Android rows.