Repository navigation
Conversation
TextLayoutManager.createLayout measured the whole string with Layout.getDesiredWidth before building a StaticLayout even when the result could not affect the layout width: for an EXACTLY width, and for boring text that did not fit (min(desired, available) is then always available). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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:
For text that is not laid out as a
BoringLayout,TextLayoutManager.createLayout(Kotlin) callsLayout.getDesiredWidth(text, paint)before building theStaticLayout. That call is a full measuring pass over the string, and its result is only needed to choose the layout width.Current behavior. The pass runs even when its result cannot matter:
EXACTLY, the result is discarded.AT_MOSTwidth, the result is redundant.boring.widthis already the unwrapped width of the same text, and it exceededfloor(width), somin(desiredWidth, floor(width))is alwaysfloor(width).For right-to-left and complex scripts
isBoringbails out early, sogetDesiredWidthis the pass that pays for shaping, and its result is then thrown away.With this change. The pass is skipped in those two cases, and the resulting layout widths are identical.
Why. Text measurement runs on the JS thread during commit. For Arabic text this pass was 37% of
createLayout.Changelog:
[ANDROID] [CHANGED] - Skip an unnecessary measuring pass when laying out
TextTest Plan:
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests "com.facebook.react.views.text.*": 60 tests, 0 failures.yarn format-check-kotlinand RNTesterassembleDebugpass.Benchmarks. RNTester release build with a text benchmark screen that is not part of this PR.
Per-function times from Perfetto with temporary trace sections. Emulator (Pixel 10 Pro AVD, API 37), the same logic on an earlier
main, medians of 4 runs, mount phase.measureContentcovers all text measurement on the JS thread:getDesiredWidthtime removedcreateLayoutmeasureContentStaticLayoutthen pays for shaping instead)BoringLayout)Untraced JS-thread CPU, current
mainvs. this branch, same emulator, 6 runs: long paragraphs −15% on mount and −29% on a text update. In the other scenarios the difference is within emulator run-to-run noise at the whole-thread level.🤖 Generated with Claude Code