Skip to content

Commit

Permalink
Pass around parentTag instead of parentShadowView (#48062)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #48062

We never need the full ShadowView representation of `parent` and this is significantly cheaper to construct and pass around.

Changelog: [Internal]

Reviewed By: rubennorte

Differential Revision: D66656411

fbshipit-source-id: 0b20e04c6beb95c498350085ec06fd57d1c11237
  • Loading branch information
javache authored and facebook-github-bot committed Dec 6, 2024
1 parent 87ec096 commit 4134b1c
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ static void RCTPerformMountInstructions(

case ShadowViewMutation::Insert: {
auto &newChildShadowView = mutation.newChildShadowView;
auto &parentShadowView = mutation.parentShadowView;
auto &newChildViewDescriptor = [registry componentViewDescriptorWithTag:newChildShadowView.tag];
auto &parentViewDescriptor = [registry componentViewDescriptorWithTag:parentShadowView.tag];
auto &parentViewDescriptor = [registry componentViewDescriptorWithTag:mutation.parentTag];

UIView<RCTComponentViewProtocol> *newChildComponentView = newChildViewDescriptor.view;

Expand All @@ -94,9 +93,8 @@ static void RCTPerformMountInstructions(

case ShadowViewMutation::Remove: {
auto &oldChildShadowView = mutation.oldChildShadowView;
auto &parentShadowView = mutation.parentShadowView;
auto &oldChildViewDescriptor = [registry componentViewDescriptorWithTag:oldChildShadowView.tag];
auto &parentViewDescriptor = [registry componentViewDescriptorWithTag:parentShadowView.tag];
auto &parentViewDescriptor = [registry componentViewDescriptorWithTag:mutation.parentTag];
[parentViewDescriptor.view unmountChildComponentView:oldChildViewDescriptor.view index:mutation.index];
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,14 @@ inline void writeInsertMountItem(
InstructionBuffer& buffer,
const CppMountItem& mountItem) {
buffer.writeIntArray(std::array<int, 3>{
mountItem.newChildShadowView.tag,
mountItem.parentShadowView.tag,
mountItem.index});
mountItem.newChildShadowView.tag, mountItem.parentTag, mountItem.index});
}

inline void writeRemoveMountItem(
InstructionBuffer& buffer,
const CppMountItem& mountItem) {
buffer.writeIntArray(std::array<int, 3>{
mountItem.oldChildShadowView.tag,
mountItem.parentShadowView.tag,
mountItem.index});
mountItem.oldChildShadowView.tag, mountItem.parentTag, mountItem.index});
}

inline void writeUpdatePropsMountItem(
Expand Down Expand Up @@ -377,7 +373,7 @@ inline void writeUpdateLayoutMountItem(

buffer.writeIntArray(std::array<int, 8>{
mountItem.newChildShadowView.tag,
mountItem.parentShadowView.tag,
mountItem.parentTag,
x,
y,
w,
Expand Down Expand Up @@ -487,7 +483,7 @@ void FabricMountingManager::executeMount(
}

for (const auto& mutation : mutations) {
const auto& parentShadowView = mutation.parentShadowView;
auto parentTag = mutation.parentTag;
const auto& oldChildShadowView = mutation.oldChildShadowView;
const auto& newChildShadowView = mutation.newChildShadowView;
auto& mutationType = mutation.type;
Expand All @@ -509,7 +505,7 @@ void FabricMountingManager::executeMount(
case ShadowViewMutation::Remove: {
if (!isVirtual) {
cppCommonMountItems.push_back(CppMountItem::RemoveMountItem(
parentShadowView, oldChildShadowView, index));
parentTag, oldChildShadowView, index));
}
break;
}
Expand Down Expand Up @@ -559,7 +555,7 @@ void FabricMountingManager::executeMount(
(maintainMutationOrder ? cppCommonMountItems
: cppUpdateLayoutMountItems)
.push_back(CppMountItem::UpdateLayoutMountItem(
mutation.newChildShadowView, parentShadowView));
mutation.newChildShadowView, parentTag));
}

// OverflowInset: This is the values indicating boundaries including
Expand Down Expand Up @@ -588,7 +584,7 @@ void FabricMountingManager::executeMount(
if (!isVirtual) {
// Insert item
cppCommonMountItems.push_back(CppMountItem::InsertMountItem(
parentShadowView, newChildShadowView, index));
parentTag, newChildShadowView, index));

bool shouldCreateView =
!allocatedViewTags.contains(newChildShadowView.tag);
Expand Down Expand Up @@ -625,7 +621,7 @@ void FabricMountingManager::executeMount(
(maintainMutationOrder ? cppCommonMountItems
: cppUpdateLayoutMountItems)
.push_back(CppMountItem::UpdateLayoutMountItem(
newChildShadowView, parentShadowView));
newChildShadowView, parentTag));

// OverflowInset: This is the values indicating boundaries including
// children of the current view. The layout of current view may not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ CppMountItem CppMountItem::DeleteMountItem(const ShadowView& shadowView) {
return {CppMountItem::Type::Delete, {}, shadowView, {}, -1};
}
CppMountItem CppMountItem::InsertMountItem(
const ShadowView& parentView,
Tag parentTag,
const ShadowView& shadowView,
int index) {
return {CppMountItem::Type::Insert, parentView, {}, shadowView, index};
return {CppMountItem::Type::Insert, parentTag, {}, shadowView, index};
}
CppMountItem CppMountItem::RemoveMountItem(
const ShadowView& parentView,
Tag parentTag,
const ShadowView& shadowView,
int index) {
return {CppMountItem::Type::Remove, parentView, shadowView, {}, index};
return {CppMountItem::Type::Remove, parentTag, shadowView, {}, index};
}
CppMountItem CppMountItem::UpdatePropsMountItem(
const ShadowView& oldShadowView,
Expand All @@ -38,20 +38,20 @@ CppMountItem CppMountItem::UpdateStateMountItem(const ShadowView& shadowView) {
}
CppMountItem CppMountItem::UpdateLayoutMountItem(
const ShadowView& shadowView,
const ShadowView& parentView) {
return {CppMountItem::Type::UpdateLayout, parentView, {}, shadowView, -1};
Tag parentTag) {
return {CppMountItem::Type::UpdateLayout, parentTag, {}, shadowView, -1};
}
CppMountItem CppMountItem::UpdateEventEmitterMountItem(
const ShadowView& shadowView) {
return {CppMountItem::Type::UpdateEventEmitter, {}, {}, shadowView, -1};
return {CppMountItem::Type::UpdateEventEmitter, -1, {}, shadowView, -1};
}
CppMountItem CppMountItem::UpdatePaddingMountItem(
const ShadowView& shadowView) {
return {CppMountItem::Type::UpdatePadding, {}, {}, shadowView, -1};
return {CppMountItem::Type::UpdatePadding, -1, {}, shadowView, -1};
}
CppMountItem CppMountItem::UpdateOverflowInsetMountItem(
const ShadowView& shadowView) {
return {CppMountItem::Type::UpdateOverflowInset, {}, {}, shadowView, -1};
return {CppMountItem::Type::UpdateOverflowInset, -1, {}, shadowView, -1};
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ struct CppMountItem final {

static CppMountItem DeleteMountItem(const ShadowView& shadowView);

static CppMountItem InsertMountItem(
const ShadowView& parentView,
const ShadowView& shadowView,
int index);
static CppMountItem
InsertMountItem(Tag parentTag, const ShadowView& shadowView, int index);

static CppMountItem RemoveMountItem(
const ShadowView& parentView,
const ShadowView& shadowView,
int index);
static CppMountItem
RemoveMountItem(Tag parentTag, const ShadowView& shadowView, int index);

static CppMountItem UpdatePropsMountItem(
const ShadowView& oldShadowView,
Expand All @@ -42,7 +38,7 @@ struct CppMountItem final {

static CppMountItem UpdateLayoutMountItem(
const ShadowView& shadowView,
const ShadowView& parentView);
Tag parentTag);

static CppMountItem UpdateEventEmitterMountItem(const ShadowView& shadowView);

Expand Down Expand Up @@ -71,7 +67,7 @@ struct CppMountItem final {
#pragma mark - Fields

Type type = {Create};
ShadowView parentShadowView = {};
Tag parentTag = -1;
ShadowView oldChildShadowView = {};
ShadowView newChildShadowView = {};
int index = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void LayoutAnimationDriver::animationMutationsForFrame(

// Create the mutation instruction
mutationsList.emplace_back(ShadowViewMutation::UpdateMutation(
keyframe.viewPrev, mutatedShadowView, keyframe.parentView));
keyframe.viewPrev, mutatedShadowView, keyframe.parentTag));

PrintMutationInstruction("Animation Progress:", mutationsList.back());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,11 @@ LayoutAnimationKeyFrameManager::pullTransaction(
keyframe.viewPrev = mutation.newChildShadowView;
if (ReactNativeFeatureFlags::
fixDifferentiatorEmittingUpdatesWithWrongParentTag()) {
keyframe.parentView = mutation.parentShadowView;
keyframe.parentTag = mutation.parentTag;
react_native_assert(
keyframe.finalMutationsForKeyFrame.size() == 1);
keyframe.finalMutationsForKeyFrame[0].parentShadowView =
mutation.parentShadowView;
keyframe.finalMutationsForKeyFrame[0].parentTag =
mutation.parentTag;
}
}
}
Expand Down Expand Up @@ -426,7 +426,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
mutation.oldChildShadowView.tag > 0) {
executeMutationImmediately =
ShadowViewMutation::RemoveMutation(
mutation.parentShadowView,
mutation.parentTag,
keyframe.viewPrev,
mutation.index);
}
Expand All @@ -449,9 +449,9 @@ LayoutAnimationKeyFrameManager::pullTransaction(
? mutation.newChildShadowView
: viewStart);
react_native_assert(viewFinal.tag > 0);
ShadowView parent = mutation.parentShadowView;
Tag parentTag = mutation.parentTag;
react_native_assert(
parent.tag > 0 ||
parentTag > 0 ||
mutation.type == ShadowViewMutation::Type::Update ||
mutation.type == ShadowViewMutation::Type::Delete);
Tag tag = viewStart.tag;
Expand Down Expand Up @@ -507,7 +507,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
/* .finalMutationsForKeyFrame = */ {},
/* .type = */ AnimationConfigurationType::Create,
/* .tag = */ tag,
/* .parentView = */ parent,
/* .parentTag = */ parentTag,
/* .viewStart = */ viewStart,
/* .viewEnd = */ viewFinal,
/* .viewPrev = */ baselineShadowView,
Expand Down Expand Up @@ -545,7 +545,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
/* .finalMutationsForKeyFrame = */ {mutation},
/* .type = */ AnimationConfigurationType::Update,
/* .tag = */ tag,
/* .parentView = */ parent,
/* .parentTag = */ parentTag,
/* .viewStart = */ viewStart,
/* .viewEnd = */ viewFinal,
/* .viewPrev = */ baselineShadowView,
Expand Down Expand Up @@ -631,7 +631,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
/* .finalMutationsForKeyFrame */ {mutation, deleteMutation},
/* .type */ AnimationConfigurationType::Delete,
/* .tag */ tag,
/* .parentView */ parent,
/* .parentTag */ parentTag,
/* .viewStart */ viewStart,
/* .viewEnd */ viewFinal,
/* .viewPrev */ baselineShadowView,
Expand Down Expand Up @@ -1184,19 +1184,17 @@ void LayoutAnimationKeyFrameManager::queueFinalMutationsForCompletedKeyFrame(
break;
case ShadowViewMutation::Type::Insert:
mutationsList.push_back(ShadowViewMutation::InsertMutation(
finalMutation.parentShadowView,
finalMutation.parentTag,
finalMutation.newChildShadowView,
finalMutation.index));
break;
case ShadowViewMutation::Type::Remove:
mutationsList.push_back(ShadowViewMutation::RemoveMutation(
finalMutation.parentShadowView, prev, finalMutation.index));
finalMutation.parentTag, prev, finalMutation.index));
break;
case ShadowViewMutation::Type::Update:
mutationsList.push_back(ShadowViewMutation::UpdateMutation(
prev,
finalMutation.newChildShadowView,
finalMutation.parentShadowView));
prev, finalMutation.newChildShadowView, finalMutation.parentTag));
break;
}
if (finalMutation.newChildShadowView.tag > 0) {
Expand All @@ -1221,7 +1219,7 @@ void LayoutAnimationKeyFrameManager::queueFinalMutationsForCompletedKeyFrame(
auto mutatedShadowView =
createInterpolatedShadowView(1, keyframe.viewStart, keyframe.viewEnd);
auto generatedPenultimateMutation = ShadowViewMutation::UpdateMutation(
keyframe.viewPrev, mutatedShadowView, keyframe.parentView);
keyframe.viewPrev, mutatedShadowView, keyframe.parentTag);
react_native_assert(
generatedPenultimateMutation.oldChildShadowView.tag > 0);
react_native_assert(
Expand All @@ -1232,7 +1230,7 @@ void LayoutAnimationKeyFrameManager::queueFinalMutationsForCompletedKeyFrame(
mutationsList.push_back(generatedPenultimateMutation);

auto generatedMutation = ShadowViewMutation::UpdateMutation(
mutatedShadowView, keyframe.viewEnd, keyframe.parentView);
mutatedShadowView, keyframe.viewEnd, keyframe.parentTag);
react_native_assert(generatedMutation.oldChildShadowView.tag > 0);
react_native_assert(generatedMutation.newChildShadowView.tag > 0);
PrintMutationInstruction(
Expand All @@ -1241,7 +1239,7 @@ void LayoutAnimationKeyFrameManager::queueFinalMutationsForCompletedKeyFrame(
mutationsList.push_back(generatedMutation);
} else {
auto mutation = ShadowViewMutation::UpdateMutation(
keyframe.viewPrev, keyframe.viewEnd, keyframe.parentView);
keyframe.viewPrev, keyframe.viewEnd, keyframe.parentTag);
PrintMutationInstruction(
logPrefix +
"Animation Complete: Queuing up Final Synthetic Mutation:",
Expand Down Expand Up @@ -1300,7 +1298,7 @@ void LayoutAnimationKeyFrameManager::

// Detect if they're in the same view hierarchy, but not equivalent
// We've already detected direct conflicts and removed them.
if (animatedKeyFrame.parentView.tag != mutation.parentShadowView.tag) {
if (animatedKeyFrame.parentTag != mutation.parentTag) {
continue;
}

Expand Down Expand Up @@ -1405,7 +1403,7 @@ void LayoutAnimationKeyFrameManager::adjustDelayedMutationIndicesForMutation(

// Detect if they're in the same view hierarchy, but not equivalent
// (We've already detected direct conflicts and handled them above)
if (animatedKeyFrame.parentView.tag != mutation.parentShadowView.tag) {
if (animatedKeyFrame.parentTag != mutation.parentTag) {
continue;
}

Expand Down Expand Up @@ -1519,8 +1517,8 @@ void LayoutAnimationKeyFrameManager::getAndEraseConflictingAnimations(
// we need to force deletion/removal to happen immediately.
bool conflicting = animatedKeyFrame.tag == baselineTag ||
(mutationIsCreateOrDelete &&
animatedKeyFrame.parentView.tag == baselineTag &&
animatedKeyFrame.parentView.tag != 0);
animatedKeyFrame.parentTag == baselineTag &&
animatedKeyFrame.parentTag != 0);

// Conflicting animation detected: if we're mutating a tag under
// animation, or deleting the parent of a tag under animation, or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct AnimationKeyFrame {
// Tag representing the node being animated.
Tag tag;

ShadowView parentView;
Tag parentTag;

// ShadowView representing the start and end points of this animation.
ShadowView viewStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ static inline bool shouldFirstComeBeforeSecondRemovesOnly(
// come first.
return (lhs.type == ShadowViewMutation::Type::Remove &&
lhs.type == rhs.type) &&
(lhs.parentShadowView.tag == rhs.parentShadowView.tag) &&
(lhs.index > rhs.index);
(lhs.parentTag == rhs.parentTag) && (lhs.index > rhs.index);
}

static inline void handleShouldFirstComeBeforeSecondRemovesOnly(
Expand All @@ -31,7 +30,7 @@ static inline void handleShouldFirstComeBeforeSecondRemovesOnly(
ShadowViewMutation::List finalList;
for (auto& mutation : list) {
if (mutation.type == ShadowViewMutation::Type::Remove) {
auto key = std::to_string(mutation.parentShadowView.tag);
auto key = std::to_string(mutation.parentTag);
removeMutationsByTag[key].push_back(mutation);
} else {
finalList.push_back(mutation);
Expand Down Expand Up @@ -104,7 +103,7 @@ static inline bool shouldFirstComeBeforeSecondMutation(
// Make sure that removes on the same level are sorted - highest indices
// must come first.
if (lhs.type == ShadowViewMutation::Type::Remove &&
lhs.parentShadowView.tag == rhs.parentShadowView.tag) {
lhs.parentTag == rhs.parentTag) {
if (lhs.index > rhs.index) {
return true;
} else {
Expand Down
Loading

0 comments on commit 4134b1c

Please sign in to comment.