Skip to content

Commit 8c53ac6

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
setup an experiment to prevent double measure of text (#44120)
Summary: Pull Request resolved: #44120 changelog: [internal] Prevent measuring the same text twice in `ParagraphShadowNode`. The current implementation calls `TextLayoutManager::measure` twice for a single `ParagraphShadowNode`. The first time to measure the node for Yoga. The second time inside `ParagraphShadowNode::layout`. I think the original author counted on the cache inside of `TextLayoutManager` to deal with this, but this is not always the case and `TextLayoutManager::measure` is called with two different available widths, leading to cache miss and fills the cache faster. Reviewed By: NickGerleman Differential Revision: D55757264 fbshipit-source-id: 0bf8b49f062f802a4e2f04cad1bf1d4bf001b870
1 parent e472979 commit 8c53ac6

21 files changed

Lines changed: 148 additions & 31 deletions

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<7c2d825e15fc7e442034a598eebb6e25>>
7+
* @generated SignedSource<<61b929b9624eeaedfa12d2f390299447>>
88
*/
99

1010
/**
@@ -106,6 +106,12 @@ public object ReactNativeFeatureFlags {
106106
@JvmStatic
107107
public fun inspectorEnableModernCDPRegistry(): Boolean = accessor.inspectorEnableModernCDPRegistry()
108108

109+
/**
110+
* When enabled, ParagraphShadowNode will no longer call measure twice.
111+
*/
112+
@JvmStatic
113+
public fun preventDoubleTextMeasure(): Boolean = accessor.preventDoubleTextMeasure()
114+
109115
/**
110116
* When enabled, it uses the modern fork of RuntimeScheduler that allows scheduling tasks with priorities from any thread.
111117
*/

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<eb3ae68166b3ec7f797a0db4b2ec1f5b>>
7+
* @generated SignedSource<<46e1a8dd088d588ea9eec703d7155710>>
88
*/
99

1010
/**
@@ -33,6 +33,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
3333
private var forceBatchingMountItemsOnAndroidCache: Boolean? = null
3434
private var inspectorEnableCxxInspectorPackagerConnectionCache: Boolean? = null
3535
private var inspectorEnableModernCDPRegistryCache: Boolean? = null
36+
private var preventDoubleTextMeasureCache: Boolean? = null
3637
private var useModernRuntimeSchedulerCache: Boolean? = null
3738
private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null
3839
private var useStateAlignmentMechanismCache: Boolean? = null
@@ -154,6 +155,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
154155
return cached
155156
}
156157

158+
override fun preventDoubleTextMeasure(): Boolean {
159+
var cached = preventDoubleTextMeasureCache
160+
if (cached == null) {
161+
cached = ReactNativeFeatureFlagsCxxInterop.preventDoubleTextMeasure()
162+
preventDoubleTextMeasureCache = cached
163+
}
164+
return cached
165+
}
166+
157167
override fun useModernRuntimeScheduler(): Boolean {
158168
var cached = useModernRuntimeSchedulerCache
159169
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<0b1377acc1a7a2bed8bd6448a54ec91a>>
7+
* @generated SignedSource<<56ac4a5eaf65775fdb757fc10ed82908>>
88
*/
99

1010
/**
@@ -54,6 +54,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
5454

5555
@DoNotStrip @JvmStatic public external fun inspectorEnableModernCDPRegistry(): Boolean
5656

57+
@DoNotStrip @JvmStatic public external fun preventDoubleTextMeasure(): Boolean
58+
5759
@DoNotStrip @JvmStatic public external fun useModernRuntimeScheduler(): Boolean
5860

5961
@DoNotStrip @JvmStatic public external fun useNativeViewConfigsInBridgelessMode(): Boolean

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<545ef5d7c16c2d6599f15a747c53cf3f>>
7+
* @generated SignedSource<<6cc4fccd13a1e426a2d6a2a24530e5e6>>
88
*/
99

1010
/**
@@ -49,6 +49,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
4949

5050
override fun inspectorEnableModernCDPRegistry(): Boolean = false
5151

52+
override fun preventDoubleTextMeasure(): Boolean = false
53+
5254
override fun useModernRuntimeScheduler(): Boolean = false
5355

5456
override fun useNativeViewConfigsInBridgelessMode(): Boolean = false

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<aa359470a22488b45abfa18b0edadb18>>
7+
* @generated SignedSource<<c1c7546acade83cf63f3c06e78352982>>
88
*/
99

1010
/**
@@ -37,6 +37,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
3737
private var forceBatchingMountItemsOnAndroidCache: Boolean? = null
3838
private var inspectorEnableCxxInspectorPackagerConnectionCache: Boolean? = null
3939
private var inspectorEnableModernCDPRegistryCache: Boolean? = null
40+
private var preventDoubleTextMeasureCache: Boolean? = null
4041
private var useModernRuntimeSchedulerCache: Boolean? = null
4142
private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null
4243
private var useStateAlignmentMechanismCache: Boolean? = null
@@ -171,6 +172,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
171172
return cached
172173
}
173174

175+
override fun preventDoubleTextMeasure(): Boolean {
176+
var cached = preventDoubleTextMeasureCache
177+
if (cached == null) {
178+
cached = currentProvider.preventDoubleTextMeasure()
179+
accessedFeatureFlags.add("preventDoubleTextMeasure")
180+
preventDoubleTextMeasureCache = cached
181+
}
182+
return cached
183+
}
184+
174185
override fun useModernRuntimeScheduler(): Boolean {
175186
var cached = useModernRuntimeSchedulerCache
176187
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<e2eef1313051abddc31e4a3340e72c1c>>
7+
* @generated SignedSource<<a5cbe59693a5f7d64af6e004951ab971>>
88
*/
99

1010
/**
@@ -49,6 +49,8 @@ public interface ReactNativeFeatureFlagsProvider {
4949

5050
@DoNotStrip public fun inspectorEnableModernCDPRegistry(): Boolean
5151

52+
@DoNotStrip public fun preventDoubleTextMeasure(): Boolean
53+
5254
@DoNotStrip public fun useModernRuntimeScheduler(): Boolean
5355

5456
@DoNotStrip public fun useNativeViewConfigsInBridgelessMode(): Boolean

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<82163a04d1e3cb54d6c5125173ab807f>>
7+
* @generated SignedSource<<f8ac6f7e857808ade5d0f26ec7924604>>
88
*/
99

1010
/**
@@ -117,6 +117,12 @@ class ReactNativeFeatureFlagsProviderHolder
117117
return method(javaProvider_);
118118
}
119119

120+
bool preventDoubleTextMeasure() override {
121+
static const auto method =
122+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("preventDoubleTextMeasure");
123+
return method(javaProvider_);
124+
}
125+
120126
bool useModernRuntimeScheduler() override {
121127
static const auto method =
122128
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useModernRuntimeScheduler");
@@ -204,6 +210,11 @@ bool JReactNativeFeatureFlagsCxxInterop::inspectorEnableModernCDPRegistry(
204210
return ReactNativeFeatureFlags::inspectorEnableModernCDPRegistry();
205211
}
206212

213+
bool JReactNativeFeatureFlagsCxxInterop::preventDoubleTextMeasure(
214+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
215+
return ReactNativeFeatureFlags::preventDoubleTextMeasure();
216+
}
217+
207218
bool JReactNativeFeatureFlagsCxxInterop::useModernRuntimeScheduler(
208219
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
209220
return ReactNativeFeatureFlags::useModernRuntimeScheduler();
@@ -275,6 +286,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
275286
makeNativeMethod(
276287
"inspectorEnableModernCDPRegistry",
277288
JReactNativeFeatureFlagsCxxInterop::inspectorEnableModernCDPRegistry),
289+
makeNativeMethod(
290+
"preventDoubleTextMeasure",
291+
JReactNativeFeatureFlagsCxxInterop::preventDoubleTextMeasure),
278292
makeNativeMethod(
279293
"useModernRuntimeScheduler",
280294
JReactNativeFeatureFlagsCxxInterop::useModernRuntimeScheduler),

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<48e337d37416ab988ea747050bf207f3>>
7+
* @generated SignedSource<<a6b8839cf6f9e87848289a8c5c37a5c8>>
88
*/
99

1010
/**
@@ -69,6 +69,9 @@ class JReactNativeFeatureFlagsCxxInterop
6969
static bool inspectorEnableModernCDPRegistry(
7070
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
7171

72+
static bool preventDoubleTextMeasure(
73+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
74+
7275
static bool useModernRuntimeScheduler(
7376
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
7477

packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<ddb65722ccc0d584d105b07a621e6871>>
7+
* @generated SignedSource<<0fe73e0526dbc2f860029b8cb0fbcfe3>>
88
*/
99

1010
/**
@@ -73,6 +73,10 @@ bool ReactNativeFeatureFlags::inspectorEnableModernCDPRegistry() {
7373
return getAccessor().inspectorEnableModernCDPRegistry();
7474
}
7575

76+
bool ReactNativeFeatureFlags::preventDoubleTextMeasure() {
77+
return getAccessor().preventDoubleTextMeasure();
78+
}
79+
7680
bool ReactNativeFeatureFlags::useModernRuntimeScheduler() {
7781
return getAccessor().useModernRuntimeScheduler();
7882
}

packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<8804fc52ad516ba82c0db6fcdea5f110>>
7+
* @generated SignedSource<<d6a33b997461fd186c58a956f6854aca>>
88
*/
99

1010
/**
@@ -102,6 +102,11 @@ class ReactNativeFeatureFlags {
102102
*/
103103
RN_EXPORT static bool inspectorEnableModernCDPRegistry();
104104

105+
/**
106+
* When enabled, ParagraphShadowNode will no longer call measure twice.
107+
*/
108+
RN_EXPORT static bool preventDoubleTextMeasure();
109+
105110
/**
106111
* When enabled, it uses the modern fork of RuntimeScheduler that allows scheduling tasks with priorities from any thread.
107112
*/

0 commit comments

Comments
 (0)