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.
  • Loading branch information
dmytrorykun committed May 7, 2024
1 parent b498834 commit 7039834
Show file tree
Hide file tree
Showing 3 changed files with 568 additions and 69 deletions.
Expand Up @@ -12,7 +12,7 @@ import type {
TouchedViewDataAtPoint,
ViewConfig,
} from './ReactNativeTypes';
import {create, diff} from './ReactNativeAttributePayload';
import {create, diff} from './ReactNativeAttributePayloadFabric';
import {dispatchEvent} from './ReactFabricEventEmitter';
import {
NoEventPriority,
Expand Down
70 changes: 2 additions & 68 deletions packages/react-native-renderer/src/ReactNativeAttributePayload.js
Expand Up @@ -15,7 +15,6 @@ import {
import isArray from 'shared/isArray';

import {enableEarlyReturnForPropDiffing} from 'shared/ReactFeatureFlags';
import {enableAddPropertiesFastPath} from 'shared/ReactFeatureFlags';

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

Expand Down Expand Up @@ -445,68 +444,6 @@ function diffProperties(
return updatePayload;
}

function fastAddProperties(
updatePayload: null | Object,
nextProps: Object,
validAttributes: AttributeConfiguration,
): null | Object {
let attributeConfig;
let nextProp;

for (const propKey in nextProps) {
nextProp = nextProps[propKey];

if (nextProp === undefined) {
continue;
}

attributeConfig = validAttributes[propKey];

if (attributeConfig === undefined) {
continue;
}

if (typeof nextProp === 'function') {
nextProp = (true: any);
}

if (typeof attributeConfig !== 'object') {
if (!updatePayload) {
updatePayload = ({}: {[string]: $FlowFixMe});
}
updatePayload[propKey] = nextProp;
continue;
}

if (typeof attributeConfig.process === 'function') {
if (!updatePayload) {
updatePayload = ({}: {[string]: $FlowFixMe});
}
updatePayload[propKey] = attributeConfig.process(nextProp);
continue;
}

if (isArray(nextProp)) {
for (let i = 0; i < nextProp.length; i++) {
updatePayload = fastAddProperties(
updatePayload,
nextProp[i],
((attributeConfig: any): AttributeConfiguration),
);
}
continue;
}

updatePayload = fastAddProperties(
updatePayload,
nextProp,
((attributeConfig: any): AttributeConfiguration),
);
}

return updatePayload;
}

/**
* addProperties adds all the valid props to the payload after being processed.
*/
Expand All @@ -515,11 +452,8 @@ function addProperties(
props: Object,
validAttributes: AttributeConfiguration,
): null | Object {
if (enableAddPropertiesFastPath) {
return fastAddProperties(updatePayload, props, validAttributes);
} else {
return diffProperties(updatePayload, emptyObject, props, validAttributes);
}
// TODO: Fast path
return diffProperties(updatePayload, emptyObject, props, validAttributes);
}

/**
Expand Down

0 comments on commit 7039834

Please sign in to comment.