Repository navigation
Parse textDecorationLine without compiling a regex on Android - #59733
Merged
Abbondanzo merged 1 commit intoNov 2, 2026
Merged
Conversation
TextAttributeProps.setTextDecorationLine split the value with "-".toRegex(), which compiles a java.util.regex.Pattern for every text fragment that has a textDecorationLine, each time the text is laid out. Splitting on the '-' character gives the same parts without a regex. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Abbondanzo
approved these changes
Nov 1, 2026
|
@Abbondanzo has imported this pull request. If you are a Meta employee, you can view this in D128941371. |
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:
On Android,
TextAttributeProps.setTextDecorationLinesplits thetextDecorationLinevalue with"-".toRegex(). That compiles a newjava.util.regex.Patternon every call. The call happens for every text fragment that has atextDecorationLine(underlines, strikethroughs, links), each time its text is laid out on the JS thread.The serialized value is
none,underline,strikethroughorunderline-strikethrough, so splitting on the'-'character gives the same parts without a regex. The old code also dropped trailing empty parts, but the loop only compares againstunderlineandstrikethrough, so they make no difference.This adds no state or cache. It only helps text with a
textDecorationLine.Changelog:
[ANDROID] [CHANGED] - Parse
textDecorationLinewithout compiling a regexTest Plan:
Unit test:
TextAttributePropsTestgetsmapBufferSetsTextDecorationLine, which checksnone,underline,strikethroughandunderline-strikethroughthroughTextAttributeProps.fromMapBuffer. It also passes without this change, because the behavior is the same.102 tests, 0 failures. ktfmt reports no changes in the two files.
Measurements: two release RNTester APKs built from this commit's base, one with and one without this change, on a Galaxy A16 and a Pixel 9a (both Android 16), compiled with
cmd package compile -m speed. Both APKs have the same temporary benchmark edits. A Playground screen shows the rows and changes some of them every 100 ms for 20 s (10 of 60 underlined rows, 20 of 100 rows with notextDecorationLine), with new strings each time so the measure cache doesn't hide the work. Each run is a fresh process, in A/B/B/A order, twice, so 4 runs per APK. JS thread CPU comes from/proc/<pid>/task/<tid>/stat. The table shows the median per changed row, with the range in brackets.textDecorationLinetextDecorationLineThe ranges for the underlined row overlap on the Pixel 9a. The row with no
textDecorationLinenever reaches this code, so it serves as a control.The row measurements above are all from this commit's base. On an older base, a simpleperf profile of a similar rich text list on a moto g57 power showed
Pattern.compileandPattern.matcherunderTextAttributeProps.fromMapBufferat 2.9% of the JS thread.Not measured: the main thread, because this code runs on the JS thread when text is laid out.
🤖 Generated with Claude Code