Create Fabric-specific version of ReactNativeAttributesPayload (#28841)

## Summary

This PR introduces Fabric-only version of
`ReactNativeAttributesPayload`. It is a copy-paste of
`ReactNativeAttributesPayload.js`, and is called
`ReactNativeAttributesPayloadFabric.js`.
The idea behind this change is that certain optimizations in prop
diffing may actually be a regression on the old architecture. For
example, removing custom diffing may result in larger updateProps
payloads. Which is, I guess, fine with JSI, but might be a problem with
the bridge.

## How did you test this change?

There should be no runtime effect of this change.

DiffTrain build for commit https://github.com/facebook/react/commit/703983426243422d9726ca3a0c7eef54e173a6bb.
This commit is contained in:
dmytrorykun
2024-05-07 10:58:19 +00:00
parent 3e4d97d674
commit acdffc09bd
4 changed files with 43 additions and 154 deletions
@@ -1 +1 @@
9b1300209eb00a2d6c645fddf6d2729d67d7b10a
703983426243422d9726ca3a0c7eef54e173a6bb
@@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<92ed224870f6202a614121cda759ff80>>
* @generated SignedSource<<b948a7523c731b45fbc28f4bfeb2bf96>>
*/
'use strict';
@@ -2341,7 +2341,6 @@ var alwaysThrottleRetries = dynamicFlags.alwaysThrottleRetries,
consoleManagedByDevToolsDuringStrictMode = dynamicFlags.consoleManagedByDevToolsDuringStrictMode,
disableDefaultPropsExceptForClasses = dynamicFlags.disableDefaultPropsExceptForClasses,
disableStringRefs = dynamicFlags.disableStringRefs,
enableAddPropertiesFastPath = dynamicFlags.enableAddPropertiesFastPath,
enableDeferRootSchedulingToMicrotask = dynamicFlags.enableDeferRootSchedulingToMicrotask,
enableEarlyReturnForPropDiffing = dynamicFlags.enableEarlyReturnForPropDiffing,
enableInfiniteRenderLoopDetection = dynamicFlags.enableInfiniteRenderLoopDetection,
@@ -3367,70 +3366,14 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
return updatePayload;
}
function fastAddProperties(updatePayload, nextProps, validAttributes) {
var attributeConfig;
var nextProp;
for (var propKey in nextProps) {
nextProp = nextProps[propKey];
if (nextProp === undefined) {
continue;
}
attributeConfig = validAttributes[propKey];
if (attributeConfig === undefined) {
continue;
}
if (typeof nextProp === 'function') {
nextProp = true;
}
if (typeof attributeConfig !== 'object') {
if (!updatePayload) {
updatePayload = {};
}
updatePayload[propKey] = nextProp;
continue;
}
if (typeof attributeConfig.process === 'function') {
if (!updatePayload) {
updatePayload = {};
}
updatePayload[propKey] = attributeConfig.process(nextProp);
continue;
}
if (isArray(nextProp)) {
for (var i = 0; i < nextProp.length; i++) {
updatePayload = fastAddProperties(updatePayload, nextProp[i], attributeConfig);
}
continue;
}
updatePayload = fastAddProperties(updatePayload, nextProp, attributeConfig);
}
return updatePayload;
}
/**
* addProperties adds all the valid props to the payload after being processed.
*/
function addProperties(updatePayload, props, validAttributes) {
if (enableAddPropertiesFastPath) {
return fastAddProperties(updatePayload, props, validAttributes);
} else {
return diffProperties(updatePayload, emptyObject$1, props, validAttributes);
}
// TODO: Fast path
return diffProperties(updatePayload, emptyObject$1, props, validAttributes);
}
/**
* clearProperties clears all the previous props by adding a null sentinel
@@ -26502,7 +26445,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
return root;
}
var ReactVersion = '19.0.0-beta-80fbc2d8';
var ReactVersion = '19.0.0-beta-303370bf';
/*
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol
@@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<6ac902add05453f485e7c7713caf3bde>>
* @generated SignedSource<<9218133e45a38bee509673d882f7b469>>
*/
"use strict";
@@ -1116,7 +1116,6 @@ var alwaysThrottleRetries = dynamicFlagsUntyped.alwaysThrottleRetries,
disableDefaultPropsExceptForClasses =
dynamicFlagsUntyped.disableDefaultPropsExceptForClasses,
disableStringRefs = dynamicFlagsUntyped.disableStringRefs,
enableAddPropertiesFastPath = dynamicFlagsUntyped.enableAddPropertiesFastPath,
enableDeferRootSchedulingToMicrotask =
dynamicFlagsUntyped.enableDeferRootSchedulingToMicrotask,
enableEarlyReturnForPropDiffing =
@@ -1480,7 +1479,12 @@ function diffNestedProperty(
function addNestedProperty(updatePayload, nextProp, validAttributes) {
if (!nextProp) return updatePayload;
if (!isArrayImpl(nextProp))
return addProperties(updatePayload, nextProp, validAttributes);
return diffProperties(
updatePayload,
emptyObject$1,
nextProp,
validAttributes
);
for (var i = 0; i < nextProp.length; i++)
updatePayload = addNestedProperty(
updatePayload,
@@ -1590,44 +1594,6 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
)))));
return updatePayload;
}
function fastAddProperties(updatePayload, nextProps, validAttributes) {
var propKey;
for (propKey in nextProps) {
var nextProp = nextProps[propKey];
if (void 0 !== nextProp) {
var attributeConfig = validAttributes[propKey];
if (void 0 !== attributeConfig)
if (
("function" === typeof nextProp && (nextProp = !0),
"object" !== typeof attributeConfig)
)
updatePayload || (updatePayload = {}),
(updatePayload[propKey] = nextProp);
else if ("function" === typeof attributeConfig.process)
updatePayload || (updatePayload = {}),
(updatePayload[propKey] = attributeConfig.process(nextProp));
else if (isArrayImpl(nextProp))
for (var i = 0; i < nextProp.length; i++)
updatePayload = fastAddProperties(
updatePayload,
nextProp[i],
attributeConfig
);
else
updatePayload = fastAddProperties(
updatePayload,
nextProp,
attributeConfig
);
}
}
return updatePayload;
}
function addProperties(updatePayload, props, validAttributes) {
return enableAddPropertiesFastPath
? fastAddProperties(updatePayload, props, validAttributes)
: diffProperties(updatePayload, emptyObject$1, props, validAttributes);
}
function mountSafeCallback_NOT_REALLY_SAFE(context, callback) {
return function () {
if (
@@ -1678,8 +1644,9 @@ var ReactNativeFiberHostComponent = (function () {
);
};
_proto.setNativeProps = function (nativeProps) {
nativeProps = addProperties(
nativeProps = diffProperties(
null,
emptyObject$1,
nativeProps,
this.viewConfig.validAttributes
);
@@ -7240,7 +7207,12 @@ function completeWork(current, workInProgress, renderLanes) {
renderLanes = rootInstanceStackCursor.current;
current = allocateTag();
type = getViewConfigForType(type);
var updatePayload = addProperties(null, newProps, type.validAttributes);
var updatePayload = diffProperties(
null,
emptyObject$1,
newProps,
type.validAttributes
);
ReactNativePrivateInterface.UIManager.createView(
current,
type.uiViewClassName,
@@ -8435,8 +8407,9 @@ function commitMutationEffectsOnFiber(finishedWork, root) {
try {
if (((newProps = root.stateNode), viewConfig)) {
var viewConfig$jscomp$0 = newProps.viewConfig;
var updatePayload$jscomp$0 = addProperties(
var updatePayload$jscomp$0 = diffProperties(
null,
emptyObject$1,
{ style: { display: "none" } },
viewConfig$jscomp$0.validAttributes
);
@@ -10808,7 +10781,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1192 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "19.0.0-beta-7fb39fd3",
version: "19.0.0-beta-11cf708a",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -10851,7 +10824,7 @@ var internals$jscomp$inline_1441 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-beta-7fb39fd3"
reconcilerVersion: "19.0.0-beta-11cf708a"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1442 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<b6bd74ab5e48f155b9407635d6f44e66>>
* @generated SignedSource<<7ec40d981bbcdacc39e55becc570911b>>
*/
"use strict";
@@ -1120,7 +1120,6 @@ var alwaysThrottleRetries = dynamicFlagsUntyped.alwaysThrottleRetries,
disableDefaultPropsExceptForClasses =
dynamicFlagsUntyped.disableDefaultPropsExceptForClasses,
disableStringRefs = dynamicFlagsUntyped.disableStringRefs,
enableAddPropertiesFastPath = dynamicFlagsUntyped.enableAddPropertiesFastPath,
enableDeferRootSchedulingToMicrotask =
dynamicFlagsUntyped.enableDeferRootSchedulingToMicrotask,
enableEarlyReturnForPropDiffing =
@@ -1484,7 +1483,12 @@ function diffNestedProperty(
function addNestedProperty(updatePayload, nextProp, validAttributes) {
if (!nextProp) return updatePayload;
if (!isArrayImpl(nextProp))
return addProperties(updatePayload, nextProp, validAttributes);
return diffProperties(
updatePayload,
emptyObject$1,
nextProp,
validAttributes
);
for (var i = 0; i < nextProp.length; i++)
updatePayload = addNestedProperty(
updatePayload,
@@ -1594,44 +1598,6 @@ function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
)))));
return updatePayload;
}
function fastAddProperties(updatePayload, nextProps, validAttributes) {
var propKey;
for (propKey in nextProps) {
var nextProp = nextProps[propKey];
if (void 0 !== nextProp) {
var attributeConfig = validAttributes[propKey];
if (void 0 !== attributeConfig)
if (
("function" === typeof nextProp && (nextProp = !0),
"object" !== typeof attributeConfig)
)
updatePayload || (updatePayload = {}),
(updatePayload[propKey] = nextProp);
else if ("function" === typeof attributeConfig.process)
updatePayload || (updatePayload = {}),
(updatePayload[propKey] = attributeConfig.process(nextProp));
else if (isArrayImpl(nextProp))
for (var i = 0; i < nextProp.length; i++)
updatePayload = fastAddProperties(
updatePayload,
nextProp[i],
attributeConfig
);
else
updatePayload = fastAddProperties(
updatePayload,
nextProp,
attributeConfig
);
}
}
return updatePayload;
}
function addProperties(updatePayload, props, validAttributes) {
return enableAddPropertiesFastPath
? fastAddProperties(updatePayload, props, validAttributes)
: diffProperties(updatePayload, emptyObject$1, props, validAttributes);
}
function mountSafeCallback_NOT_REALLY_SAFE(context, callback) {
return function () {
if (
@@ -1682,8 +1648,9 @@ var ReactNativeFiberHostComponent = (function () {
);
};
_proto.setNativeProps = function (nativeProps) {
nativeProps = addProperties(
nativeProps = diffProperties(
null,
emptyObject$1,
nativeProps,
this.viewConfig.validAttributes
);
@@ -7506,7 +7473,12 @@ function completeWork(current, workInProgress, renderLanes) {
renderLanes = rootInstanceStackCursor.current;
current = allocateTag();
type = getViewConfigForType(type);
var updatePayload = addProperties(null, newProps, type.validAttributes);
var updatePayload = diffProperties(
null,
emptyObject$1,
newProps,
type.validAttributes
);
ReactNativePrivateInterface.UIManager.createView(
current,
type.uiViewClassName,
@@ -8918,8 +8890,9 @@ function commitMutationEffectsOnFiber(finishedWork, root) {
try {
if (((newProps = root.stateNode), viewConfig)) {
var viewConfig$jscomp$0 = newProps.viewConfig;
var updatePayload$jscomp$0 = addProperties(
var updatePayload$jscomp$0 = diffProperties(
null,
emptyObject$1,
{ style: { display: "none" } },
viewConfig$jscomp$0.validAttributes
);
@@ -11514,7 +11487,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1272 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "19.0.0-beta-350ccbc3",
version: "19.0.0-beta-fa7474ba",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -11570,7 +11543,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-beta-350ccbc3"
reconcilerVersion: "19.0.0-beta-fa7474ba"
});
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
computeComponentStackForErrorReporting: function (reactTag) {