Skip to content

Commit bb9a24d

Browse files
authored
Use fastAddProperties in diffing (#32243)
## Summary `fastAddProperties` has shown some perf benefits when used for creating props payload for new components. In this PR we'll try to use it for diffing props for existing components. It would be good enough if it simply doesn't regress perf. We'll be able to delete the old `addProperties`, and make `fastAddProperties` the default behaviour. ## How did you test this change? ``` yarn lint yarn flow native yarn test packages/react-native-renderer -r=xplat --variant=false yarn test packages/react-native-renderer -r=xplat --variant=true ```
1 parent b2357ec commit bb9a24d

10 files changed

+19
-2
lines changed

packages/react-native-renderer/src/ReactNativeAttributePayloadFabric.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import {
1414
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
1515
import isArray from 'shared/isArray';
1616

17-
import {enableShallowPropDiffing} from 'shared/ReactFeatureFlags';
17+
import {
18+
enableShallowPropDiffing,
19+
enableFastAddPropertiesInDiffing,
20+
} from 'shared/ReactFeatureFlags';
1821

1922
import type {AttributeConfiguration} from './ReactNativeTypes';
2023

@@ -218,7 +221,11 @@ function addNestedProperty(
218221

219222
if (!isArray(nextProp)) {
220223
// Add each property of the leaf.
221-
return addProperties(updatePayload, nextProp, validAttributes);
224+
if (enableFastAddPropertiesInDiffing) {
225+
return fastAddProperties(updatePayload, nextProp, validAttributes);
226+
} else {
227+
return addProperties(updatePayload, nextProp, validAttributes);
228+
}
222229
}
223230

224231
for (let i = 0; i < nextProp.length; i++) {

packages/shared/ReactFeatureFlags.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ export const enableInfiniteRenderLoopDetection = false;
157157
*/
158158
export const enableUseResourceEffectHook = false;
159159

160+
export const enableFastAddPropertiesInDiffing = true;
161+
160162
// -----------------------------------------------------------------------------
161163
// Ready for next major.
162164
//

packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ export const enableSiblingPrerendering = __VARIANT__;
2828
export const enableUseResourceEffectHook = __VARIANT__;
2929
export const enableOwnerStacks = __VARIANT__;
3030
export const enableRemoveConsolePatches = __VARIANT__;
31+
export const enableFastAddPropertiesInDiffing = __VARIANT__;

packages/shared/forks/ReactFeatureFlags.native-fb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const {
3030
enableSiblingPrerendering,
3131
enableOwnerStacks,
3232
enableRemoveConsolePatches,
33+
enableFastAddPropertiesInDiffing,
3334
} = dynamicFlags;
3435

3536
// The rest of the flags are static for better dead code elimination.

packages/shared/forks/ReactFeatureFlags.native-oss.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const enableYieldingBeforePassive = false;
7272

7373
export const enableThrottledScheduling = false;
7474
export const enableViewTransition = false;
75+
export const enableFastAddPropertiesInDiffing = false;
7576

7677
// Profiling Only
7778
export const enableProfilerTimer = __PROFILE__;

packages/shared/forks/ReactFeatureFlags.test-renderer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export const enableYieldingBeforePassive = true;
7171

7272
export const enableThrottledScheduling = false;
7373
export const enableViewTransition = false;
74+
export const enableFastAddPropertiesInDiffing = true;
7475

7576
// TODO: This must be in sync with the main ReactFeatureFlags file because
7677
// the Test Renderer's value must be the same as the one used by the

packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const enableYieldingBeforePassive = false;
6969
export const enableThrottledScheduling = false;
7070
export const enableViewTransition = false;
7171
export const enableRemoveConsolePatches = false;
72+
export const enableFastAddPropertiesInDiffing = false;
7273

7374
// Flow magic to verify the exports of this file match the original version.
7475
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

packages/shared/forks/ReactFeatureFlags.test-renderer.www.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const enableYieldingBeforePassive = false;
8484
export const enableThrottledScheduling = false;
8585
export const enableViewTransition = false;
8686
export const enableRemoveConsolePatches = false;
87+
export const enableFastAddPropertiesInDiffing = false;
8788

8889
// Flow magic to verify the exports of this file match the original version.
8990
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

packages/shared/forks/ReactFeatureFlags.www-dynamic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const enableSiblingPrerendering = __VARIANT__;
3838

3939
export const enableUseResourceEffectHook = __VARIANT__;
4040
export const enableRemoveConsolePatches = __VARIANT__;
41+
export const enableFastAddPropertiesInDiffing = __VARIANT__;
4142

4243
// TODO: These flags are hard-coded to the default values used in open source.
4344
// Update the tests so that they pass in either mode, then set these

packages/shared/forks/ReactFeatureFlags.www.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const {
3737
transitionLaneExpirationMs,
3838
enableOwnerStacks,
3939
enableRemoveConsolePatches,
40+
enableFastAddPropertiesInDiffing,
4041
} = dynamicFeatureFlags;
4142

4243
// On WWW, __EXPERIMENTAL__ is used for a new modern build.

0 commit comments

Comments
 (0)