Skip to content

Commit

Permalink
Use fastAddProperties in diffing (#32243)
Browse files Browse the repository at this point in the history
## 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
```
  • Loading branch information
dmytrorykun authored Jan 30, 2025
1 parent b2357ec commit bb9a24d
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
import isArray from 'shared/isArray';

import {enableShallowPropDiffing} from 'shared/ReactFeatureFlags';
import {
enableShallowPropDiffing,
enableFastAddPropertiesInDiffing,
} from 'shared/ReactFeatureFlags';

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

Expand Down Expand Up @@ -218,7 +221,11 @@ function addNestedProperty(

if (!isArray(nextProp)) {
// Add each property of the leaf.
return addProperties(updatePayload, nextProp, validAttributes);
if (enableFastAddPropertiesInDiffing) {
return fastAddProperties(updatePayload, nextProp, validAttributes);
} else {
return addProperties(updatePayload, nextProp, validAttributes);
}
}

for (let i = 0; i < nextProp.length; i++) {
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export const enableInfiniteRenderLoopDetection = false;
*/
export const enableUseResourceEffectHook = false;

export const enableFastAddPropertiesInDiffing = true;

// -----------------------------------------------------------------------------
// Ready for next major.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ export const enableSiblingPrerendering = __VARIANT__;
export const enableUseResourceEffectHook = __VARIANT__;
export const enableOwnerStacks = __VARIANT__;
export const enableRemoveConsolePatches = __VARIANT__;
export const enableFastAddPropertiesInDiffing = __VARIANT__;
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const {
enableSiblingPrerendering,
enableOwnerStacks,
enableRemoveConsolePatches,
enableFastAddPropertiesInDiffing,
} = dynamicFlags;

// The rest of the flags are static for better dead code elimination.
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const enableYieldingBeforePassive = false;

export const enableThrottledScheduling = false;
export const enableViewTransition = false;
export const enableFastAddPropertiesInDiffing = false;

// Profiling Only
export const enableProfilerTimer = __PROFILE__;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const enableYieldingBeforePassive = true;

export const enableThrottledScheduling = false;
export const enableViewTransition = false;
export const enableFastAddPropertiesInDiffing = true;

// TODO: This must be in sync with the main ReactFeatureFlags file because
// the Test Renderer's value must be the same as the one used by the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const enableYieldingBeforePassive = false;
export const enableThrottledScheduling = false;
export const enableViewTransition = false;
export const enableRemoveConsolePatches = false;
export const enableFastAddPropertiesInDiffing = false;

// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const enableYieldingBeforePassive = false;
export const enableThrottledScheduling = false;
export const enableViewTransition = false;
export const enableRemoveConsolePatches = false;
export const enableFastAddPropertiesInDiffing = false;

// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.www-dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const enableSiblingPrerendering = __VARIANT__;

export const enableUseResourceEffectHook = __VARIANT__;
export const enableRemoveConsolePatches = __VARIANT__;
export const enableFastAddPropertiesInDiffing = __VARIANT__;

// TODO: These flags are hard-coded to the default values used in open source.
// Update the tests so that they pass in either mode, then set these
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const {
transitionLaneExpirationMs,
enableOwnerStacks,
enableRemoveConsolePatches,
enableFastAddPropertiesInDiffing,
} = dynamicFeatureFlags;

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

0 comments on commit bb9a24d

Please sign in to comment.