mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Add early return to diffProperties (#28842)
## Summary This PR adds early return to the `diff` function. We don't need to go through all the entries of `nextProps`, process and deep-diff the values if `nextProps` is the same object as `prevProps`. Roughly 6% of all `diffProperties` calls can be skipped. ## How did you test this change? RNTester.
This commit is contained in:
@@ -14,6 +14,8 @@ import {
|
||||
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
import {enableEarlyReturnForPropDiffing} from 'shared/ReactFeatureFlags';
|
||||
|
||||
import type {AttributeConfiguration} from './ReactNativeTypes';
|
||||
|
||||
const emptyObject = {};
|
||||
@@ -483,6 +485,11 @@ export function diff(
|
||||
nextProps: Object,
|
||||
validAttributes: AttributeConfiguration,
|
||||
): null | Object {
|
||||
if (enableEarlyReturnForPropDiffing) {
|
||||
if (prevProps === nextProps) {
|
||||
return null; // no change
|
||||
}
|
||||
}
|
||||
return diffProperties(
|
||||
null, // updatePayload
|
||||
prevProps,
|
||||
|
||||
@@ -119,6 +119,8 @@ export const passChildrenWhenCloningPersistedNodes = false;
|
||||
|
||||
export const enableServerComponentLogs = __EXPERIMENTAL__;
|
||||
|
||||
export const enableEarlyReturnForPropDiffing = false;
|
||||
|
||||
/**
|
||||
* Enables an expiration time for retry lanes to avoid starvation.
|
||||
*/
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
export const alwaysThrottleRetries = __VARIANT__;
|
||||
export const consoleManagedByDevToolsDuringStrictMode = __VARIANT__;
|
||||
export const enableAsyncActions = __VARIANT__;
|
||||
export const enableEarlyReturnForPropDiffing = __VARIANT__;
|
||||
export const enableComponentStackLocations = __VARIANT__;
|
||||
export const enableDeferRootSchedulingToMicrotask = __VARIANT__;
|
||||
export const enableInfiniteRenderLoopDetection = __VARIANT__;
|
||||
|
||||
@@ -22,6 +22,7 @@ export const {
|
||||
alwaysThrottleRetries,
|
||||
consoleManagedByDevToolsDuringStrictMode,
|
||||
enableAsyncActions,
|
||||
enableEarlyReturnForPropDiffing,
|
||||
enableComponentStackLocations,
|
||||
enableDeferRootSchedulingToMicrotask,
|
||||
enableInfiniteRenderLoopDetection,
|
||||
|
||||
@@ -101,6 +101,7 @@ export const allowConcurrentByDefault = false;
|
||||
export const enableTransitionTracing = false;
|
||||
export const enableDO_NOT_USE_disableStrictPassiveEffect = false;
|
||||
export const passChildrenWhenCloningPersistedNodes = false;
|
||||
export const enableEarlyReturnForPropDiffing = false;
|
||||
|
||||
// Profiling Only
|
||||
export const enableProfilerTimer = __PROFILE__;
|
||||
|
||||
@@ -76,6 +76,7 @@ export const disableClientCache = true;
|
||||
export const enableServerComponentKeys = true;
|
||||
export const enableServerComponentLogs = true;
|
||||
export const enableInfiniteRenderLoopDetection = false;
|
||||
export const enableEarlyReturnForPropDiffing = false;
|
||||
|
||||
// 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
|
||||
|
||||
@@ -87,6 +87,7 @@ export const disableLegacyMode = false;
|
||||
export const disableDOMTestUtils = false;
|
||||
|
||||
export const disableDefaultPropsExceptForClasses = false;
|
||||
export const enableEarlyReturnForPropDiffing = false;
|
||||
|
||||
// Flow magic to verify the exports of this file match the original version.
|
||||
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
|
||||
|
||||
@@ -87,6 +87,7 @@ export const disableLegacyMode = false;
|
||||
export const disableDOMTestUtils = false;
|
||||
|
||||
export const disableDefaultPropsExceptForClasses = false;
|
||||
export const enableEarlyReturnForPropDiffing = false;
|
||||
|
||||
// Flow magic to verify the exports of this file match the original version.
|
||||
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
|
||||
|
||||
@@ -117,6 +117,7 @@ export const disableStringRefs = false;
|
||||
export const disableLegacyMode = __EXPERIMENTAL__;
|
||||
|
||||
export const disableDOMTestUtils = false;
|
||||
export const enableEarlyReturnForPropDiffing = false;
|
||||
|
||||
// Flow magic to verify the exports of this file match the original version.
|
||||
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
|
||||
|
||||
Reference in New Issue
Block a user