Skip to content

Commit

Permalink
Create Fabric-specific version of ReactNativeAttributesPayload (#28841)
Browse files Browse the repository at this point in the history
## 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 7039834.
  • Loading branch information
dmytrorykun committed May 7, 2024
1 parent 3e4d97d commit acdffc0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 154 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9b1300209eb00a2d6c645fddf6d2729d67d7b10a
703983426243422d9726ca3a0c7eef54e173a6bb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<92ed224870f6202a614121cda759ff80>>
* @generated SignedSource<<b948a7523c731b45fbc28f4bfeb2bf96>>
*/

'use strict';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<6ac902add05453f485e7c7713caf3bde>>
* @generated SignedSource<<9218133e45a38bee509673d882f7b469>>
*/

"use strict";
Expand Down Expand Up @@ -1116,7 +1116,6 @@ var alwaysThrottleRetries = dynamicFlagsUntyped.alwaysThrottleRetries,
disableDefaultPropsExceptForClasses =
dynamicFlagsUntyped.disableDefaultPropsExceptForClasses,
disableStringRefs = dynamicFlagsUntyped.disableStringRefs,
enableAddPropertiesFastPath = dynamicFlagsUntyped.enableAddPropertiesFastPath,
enableDeferRootSchedulingToMicrotask =
dynamicFlagsUntyped.enableDeferRootSchedulingToMicrotask,
enableEarlyReturnForPropDiffing =
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -1678,8 +1644,9 @@ var ReactNativeFiberHostComponent = (function () {
);
};
_proto.setNativeProps = function (nativeProps) {
nativeProps = addProperties(
nativeProps = diffProperties(
null,
emptyObject$1,
nativeProps,
this.viewConfig.validAttributes
);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<b6bd74ab5e48f155b9407635d6f44e66>>
* @generated SignedSource<<7ec40d981bbcdacc39e55becc570911b>>
*/

"use strict";
Expand Down Expand Up @@ -1120,7 +1120,6 @@ var alwaysThrottleRetries = dynamicFlagsUntyped.alwaysThrottleRetries,
disableDefaultPropsExceptForClasses =
dynamicFlagsUntyped.disableDefaultPropsExceptForClasses,
disableStringRefs = dynamicFlagsUntyped.disableStringRefs,
enableAddPropertiesFastPath = dynamicFlagsUntyped.enableAddPropertiesFastPath,
enableDeferRootSchedulingToMicrotask =
dynamicFlagsUntyped.enableDeferRootSchedulingToMicrotask,
enableEarlyReturnForPropDiffing =
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -1682,8 +1648,9 @@ var ReactNativeFiberHostComponent = (function () {
);
};
_proto.setNativeProps = function (nativeProps) {
nativeProps = addProperties(
nativeProps = diffProperties(
null,
emptyObject$1,
nativeProps,
this.viewConfig.validAttributes
);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit acdffc0

Please sign in to comment.