Repository navigation
Defer PreparedLayout reactTags attachment to mount on Android (#60579) - #60579
Open
Abbondanzo wants to merge 1 commit into
Open
Abbondanzo wants to merge 1 commit into
Abbondanzo wants to merge 1 commit into
Conversation
|
@Abbondanzo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D136369766. |
…60579) Summary: When `enablePreparedTextLayout` is enabled on Android, a `preparedTextCache_` hit whose fragment React tags differ from the cached entry currently calls `reusePreparedLayoutWithNewReactTags` during `TextLayoutManager::prepareLayout` and wraps the cloned `PreparedLayout` in a brand-new `jni::global_ref`. Under heavy list/navigation churn or screens with repeated text strings, each tag-divergent `ParagraphShadowNode` holds an uncached JNI global reference for its lifetime, multiplying global-reference table usage well beyond `preparedTextCacheSize`. Add the `deferPreparedLayoutReactTagsToMountAndroid` feature flag (default `false`). When enabled, `TextLayoutManager::prepareLayout` shares the cached `PreparedTextLayout` global reference across tag-divergent nodes (marking it as having divergent tags) without crossing JNI or allocating a new global reference on the layout thread. At mount time, `ParagraphState::getJNIReference` attaches the node's fragment tags via `PreparedLayout.withReactTags` and returns a `jni::local_ref`, so the tag-specific wrapper lives strictly on the Java heap until the view drops or recycles it. Changelog: [Android][Changed] - Add `deferPreparedLayoutReactTagsToMountAndroid` feature flag to share cached `PreparedLayout` JNI global references across differing React tags and attach new tags via a local reference on mount Signed-off-by: Peter Abbondanzo <abbo@meta.com> Differential Revision: D136369766
Abbondanzo
force-pushed
the
export-D136369766
branch
from
December 5, 2026 16:45
22f7871 to
44e050b
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:
When
enablePreparedTextLayoutis enabled on Android, apreparedTextCache_hit whose fragment React tags differ from the cached entry currently callsreusePreparedLayoutWithNewReactTagsduringTextLayoutManager::prepareLayoutand wraps the clonedPreparedLayoutin a brand-newjni::global_ref. Under heavy list/navigation churn or screens with repeated text strings, each tag-divergentParagraphShadowNodeholds an uncached JNI global reference for its lifetime, multiplying global-reference table usage well beyondpreparedTextCacheSize.Add the
deferPreparedLayoutReactTagsToMountAndroidfeature flag (defaultfalse). When enabled,TextLayoutManager::prepareLayoutshares the cachedPreparedTextLayoutglobal reference across tag-divergent nodes (marking it as having divergent tags) without crossing JNI or allocating a new global reference on the layout thread. At mount time,ParagraphState::getJNIReferenceattaches the node's fragment tags viaPreparedLayout.withReactTagsand returns ajni::local_ref, so the tag-specific wrapper lives strictly on the Java heap until the view drops or recycles it.Benchmarks (
RNTester, Android arm64 Release, AOT speed-compiled)Single-binary runtime flag toggle, 1 discarded warmup + 6 alternating cold launches per arm (medians).
Static 1,000mounts 1,000<Text>views sharing 10 strings;Tag churnremounts 60 rows × 2<Text>views for 120 ticks (14,400 tag-reuse mounts per run):deferPreparedLayoutReactTagsToMountAndroid = trueART HPROF verification on
Static 1,000(RNTesterdebug, Android API 35 x86_64):PreparedLayoutJNI global roots dropped from 1,054 → 63 (tag-reuse global roots 991 → 0; all 991 view-held wrappers live purely on the Java heap).Changelog:
[Android][Changed] - Add
deferPreparedLayoutReactTagsToMountAndroidfeature flag to share cachedPreparedLayoutJNI global references across differing React tags and attach new tags via a local reference on mountSigned-off-by: Peter Abbondanzo abbo@meta.com
Differential Revision: D136369766