Repository navigation
Skip redrawing iOS Text when only its position changes - #59155
Open
hryhoriiK97 wants to merge 1 commit into
Open
hryhoriiK97 wants to merge 1 commit into
hryhoriiK97 wants to merge 1 commit into
Conversation
`RCTParagraphComponentView` requested a redraw on every layout metrics update and on every state update. Both fire for a paragraph that merely moved: the mounting layer sends layout metrics whenever the origin changes, and a relayout gives the paragraph a new state even with unchanged text, because the attributed string records each fragment's layout metrics. A reflow above a list therefore redrew every paragraph below it. Text is drawn relative to the view's own bounds and content frame, from the content and paragraph attributes in its state. Redraw only when one of those, or the pixel density, changed. Strings with inline views keep redrawing on every state, since attachment sizes come from the layout metrics the content comparison ignores. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
hryhoriiK97
force-pushed
the
ios-text-skip-position-redraw
branch
from
October 16, 2026 23:19
69e6b87 to
d387cce
Compare
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:
RCTParagraphComponentViewdraws its text in a childRCTParagraphTextView, positioned at the paragraph's content frame within the view's own bounds.Current behavior. The view requests a redraw of its text on every layout metrics update and on every state update. Both fire for a paragraph that has merely moved:
AttributedStringequality includes each fragment'sparentShadowView, whose layout metrics changed, soParagraphShadowNode::updateStateIfNeededsees a different string.So when the content above a paragraph changes height, every paragraph below it re-runs TextKit layout and glyph rasterization, although its bounds, padding and text are unchanged. A row inserted at the top of a non-virtualized list redraws every label under it.
With this change. A redraw is requested only when something the drawing depends on changed:
updateLayoutMetrics:, the view's frame size, its content frame (which carries the content insets the drawing origin is derived from), or the pixel scale factor;updateState:, the text content (AttributedString::isContentEqual, which compares strings and text attributes but not layout metrics) or the paragraph attributes. A string containing inline views keeps redrawing on every state, since attachment sizes come from the layout metrics the content comparison ignores.A recycled view always receives a new state before it is displayed, and the first state of a view always redraws, so neither comparison can skip a needed redraw.
Why. Text drawing is the most expensive per-view work on the main thread during a reflow, and none of it is needed when the paragraph only moved.
Changelog:
[IOS] [FIXED] - Text no longer redraws when only its position changes, such as when content above it changes height
Test Plan:
node scripts/clang-format.js --checkon the changed file passes.xcodebuildfor the iPhone 16 Pro simulator (Debug) and for a physical iPhone 15 Pro (Release); the Text examples render as before, including after content above a paragraph changes height, after a paragraph's own size changes, and after a text change with unchanged metrics.ScrollView; a "reflow" toggles the height of a spacer above the labels from 0 to 40 pt, so every label moves and none changes size. Timed from Fabric's transaction telemetry, a run-loop observer after the CoreAnimation commit (mount end to display), a timer around-[RCTParagraphTextView drawRect:], and thetouchendEvent Timing entry for the press (press to mount end). The two arms are the same binary with the new checks switched by an environment variable. iPhone 15 Pro, Release, medians of 5 presses:drawRecttotal, system fontdrawRecttotal,fontFamily: 'Avenir'The one remaining redraw is the harness's own status label, whose text changes. Press-to-mount also drops because the main thread no longer spends the previous frame drawing before it can run the next mount. Mounting, unmounting and text changes are unchanged within noise: mounting the same 1000 labels measures 113 ms to display in both arms.
🤖 Generated with Claude Code