Skip to content

Commit 4134b1c

Browse files
javachefacebook-github-bot
authored andcommitted
Pass around parentTag instead of parentShadowView (#48062)
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
1 parent 87ec096 commit 4134b1c

File tree

14 files changed

+188
-177
lines changed

14 files changed

+188
-177
lines changed

packages/react-native/React/Fabric/Mounting/RCTMountingManager.mm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ static void RCTPerformMountInstructions(
7373

7474
case ShadowViewMutation::Insert: {
7575
auto &newChildShadowView = mutation.newChildShadowView;
76-
auto &parentShadowView = mutation.parentShadowView;
7776
auto &newChildViewDescriptor = [registry componentViewDescriptorWithTag:newChildShadowView.tag];
78-
auto &parentViewDescriptor = [registry componentViewDescriptorWithTag:parentShadowView.tag];
77+
auto &parentViewDescriptor = [registry componentViewDescriptorWithTag:mutation.parentTag];
7978

8079
UIView<RCTComponentViewProtocol> *newChildComponentView = newChildViewDescriptor.view;
8180

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

9594
case ShadowViewMutation::Remove: {
9695
auto &oldChildShadowView = mutation.oldChildShadowView;
97-
auto &parentShadowView = mutation.parentShadowView;
9896
auto &oldChildViewDescriptor = [registry componentViewDescriptorWithTag:oldChildShadowView.tag];
99-
auto &parentViewDescriptor = [registry componentViewDescriptorWithTag:parentShadowView.tag];
97+
auto &parentViewDescriptor = [registry componentViewDescriptorWithTag:mutation.parentTag];
10098
[parentViewDescriptor.view unmountChildComponentView:oldChildViewDescriptor.view index:mutation.index];
10199
break;
102100
}

packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,18 +320,14 @@ inline void writeInsertMountItem(
320320
InstructionBuffer& buffer,
321321
const CppMountItem& mountItem) {
322322
buffer.writeIntArray(std::array<int, 3>{
323-
mountItem.newChildShadowView.tag,
324-
mountItem.parentShadowView.tag,
325-
mountItem.index});
323+
mountItem.newChildShadowView.tag, mountItem.parentTag, mountItem.index});
326324
}
327325

328326
inline void writeRemoveMountItem(
329327
InstructionBuffer& buffer,
330328
const CppMountItem& mountItem) {
331329
buffer.writeIntArray(std::array<int, 3>{
332-
mountItem.oldChildShadowView.tag,
333-
mountItem.parentShadowView.tag,
334-
mountItem.index});
330+
mountItem.oldChildShadowView.tag, mountItem.parentTag, mountItem.index});
335331
}
336332

337333
inline void writeUpdatePropsMountItem(
@@ -377,7 +373,7 @@ inline void writeUpdateLayoutMountItem(
377373

378374
buffer.writeIntArray(std::array<int, 8>{
379375
mountItem.newChildShadowView.tag,
380-
mountItem.parentShadowView.tag,
376+
mountItem.parentTag,
381377
x,
382378
y,
383379
w,
@@ -487,7 +483,7 @@ void FabricMountingManager::executeMount(
487483
}
488484

489485
for (const auto& mutation : mutations) {
490-
const auto& parentShadowView = mutation.parentShadowView;
486+
auto parentTag = mutation.parentTag;
491487
const auto& oldChildShadowView = mutation.oldChildShadowView;
492488
const auto& newChildShadowView = mutation.newChildShadowView;
493489
auto& mutationType = mutation.type;
@@ -509,7 +505,7 @@ void FabricMountingManager::executeMount(
509505
case ShadowViewMutation::Remove: {
510506
if (!isVirtual) {
511507
cppCommonMountItems.push_back(CppMountItem::RemoveMountItem(
512-
parentShadowView, oldChildShadowView, index));
508+
parentTag, oldChildShadowView, index));
513509
}
514510
break;
515511
}
@@ -559,7 +555,7 @@ void FabricMountingManager::executeMount(
559555
(maintainMutationOrder ? cppCommonMountItems
560556
: cppUpdateLayoutMountItems)
561557
.push_back(CppMountItem::UpdateLayoutMountItem(
562-
mutation.newChildShadowView, parentShadowView));
558+
mutation.newChildShadowView, parentTag));
563559
}
564560

565561
// OverflowInset: This is the values indicating boundaries including
@@ -588,7 +584,7 @@ void FabricMountingManager::executeMount(
588584
if (!isVirtual) {
589585
// Insert item
590586
cppCommonMountItems.push_back(CppMountItem::InsertMountItem(
591-
parentShadowView, newChildShadowView, index));
587+
parentTag, newChildShadowView, index));
592588

593589
bool shouldCreateView =
594590
!allocatedViewTags.contains(newChildShadowView.tag);
@@ -625,7 +621,7 @@ void FabricMountingManager::executeMount(
625621
(maintainMutationOrder ? cppCommonMountItems
626622
: cppUpdateLayoutMountItems)
627623
.push_back(CppMountItem::UpdateLayoutMountItem(
628-
newChildShadowView, parentShadowView));
624+
newChildShadowView, parentTag));
629625

630626
// OverflowInset: This is the values indicating boundaries including
631627
// children of the current view. The layout of current view may not

packages/react-native/ReactAndroid/src/main/jni/react/fabric/MountItem.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ CppMountItem CppMountItem::DeleteMountItem(const ShadowView& shadowView) {
1616
return {CppMountItem::Type::Delete, {}, shadowView, {}, -1};
1717
}
1818
CppMountItem CppMountItem::InsertMountItem(
19-
const ShadowView& parentView,
19+
Tag parentTag,
2020
const ShadowView& shadowView,
2121
int index) {
22-
return {CppMountItem::Type::Insert, parentView, {}, shadowView, index};
22+
return {CppMountItem::Type::Insert, parentTag, {}, shadowView, index};
2323
}
2424
CppMountItem CppMountItem::RemoveMountItem(
25-
const ShadowView& parentView,
25+
Tag parentTag,
2626
const ShadowView& shadowView,
2727
int index) {
28-
return {CppMountItem::Type::Remove, parentView, shadowView, {}, index};
28+
return {CppMountItem::Type::Remove, parentTag, shadowView, {}, index};
2929
}
3030
CppMountItem CppMountItem::UpdatePropsMountItem(
3131
const ShadowView& oldShadowView,
@@ -38,20 +38,20 @@ CppMountItem CppMountItem::UpdateStateMountItem(const ShadowView& shadowView) {
3838
}
3939
CppMountItem CppMountItem::UpdateLayoutMountItem(
4040
const ShadowView& shadowView,
41-
const ShadowView& parentView) {
42-
return {CppMountItem::Type::UpdateLayout, parentView, {}, shadowView, -1};
41+
Tag parentTag) {
42+
return {CppMountItem::Type::UpdateLayout, parentTag, {}, shadowView, -1};
4343
}
4444
CppMountItem CppMountItem::UpdateEventEmitterMountItem(
4545
const ShadowView& shadowView) {
46-
return {CppMountItem::Type::UpdateEventEmitter, {}, {}, shadowView, -1};
46+
return {CppMountItem::Type::UpdateEventEmitter, -1, {}, shadowView, -1};
4747
}
4848
CppMountItem CppMountItem::UpdatePaddingMountItem(
4949
const ShadowView& shadowView) {
50-
return {CppMountItem::Type::UpdatePadding, {}, {}, shadowView, -1};
50+
return {CppMountItem::Type::UpdatePadding, -1, {}, shadowView, -1};
5151
}
5252
CppMountItem CppMountItem::UpdateOverflowInsetMountItem(
5353
const ShadowView& shadowView) {
54-
return {CppMountItem::Type::UpdateOverflowInset, {}, {}, shadowView, -1};
54+
return {CppMountItem::Type::UpdateOverflowInset, -1, {}, shadowView, -1};
5555
}
5656

5757
} // namespace facebook::react

packages/react-native/ReactAndroid/src/main/jni/react/fabric/MountItem.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,11 @@ struct CppMountItem final {
2424

2525
static CppMountItem DeleteMountItem(const ShadowView& shadowView);
2626

27-
static CppMountItem InsertMountItem(
28-
const ShadowView& parentView,
29-
const ShadowView& shadowView,
30-
int index);
27+
static CppMountItem
28+
InsertMountItem(Tag parentTag, const ShadowView& shadowView, int index);
3129

32-
static CppMountItem RemoveMountItem(
33-
const ShadowView& parentView,
34-
const ShadowView& shadowView,
35-
int index);
30+
static CppMountItem
31+
RemoveMountItem(Tag parentTag, const ShadowView& shadowView, int index);
3632

3733
static CppMountItem UpdatePropsMountItem(
3834
const ShadowView& oldShadowView,
@@ -42,7 +38,7 @@ struct CppMountItem final {
4238

4339
static CppMountItem UpdateLayoutMountItem(
4440
const ShadowView& shadowView,
45-
const ShadowView& parentView);
41+
Tag parentTag);
4642

4743
static CppMountItem UpdateEventEmitterMountItem(const ShadowView& shadowView);
4844

@@ -71,7 +67,7 @@ struct CppMountItem final {
7167
#pragma mark - Fields
7268

7369
Type type = {Create};
74-
ShadowView parentShadowView = {};
70+
Tag parentTag = -1;
7571
ShadowView oldChildShadowView = {};
7672
ShadowView newChildShadowView = {};
7773
int index = {};

packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void LayoutAnimationDriver::animationMutationsForFrame(
5656

5757
// Create the mutation instruction
5858
mutationsList.emplace_back(ShadowViewMutation::UpdateMutation(
59-
keyframe.viewPrev, mutatedShadowView, keyframe.parentView));
59+
keyframe.viewPrev, mutatedShadowView, keyframe.parentTag));
6060

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

packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,11 @@ LayoutAnimationKeyFrameManager::pullTransaction(
394394
keyframe.viewPrev = mutation.newChildShadowView;
395395
if (ReactNativeFeatureFlags::
396396
fixDifferentiatorEmittingUpdatesWithWrongParentTag()) {
397-
keyframe.parentView = mutation.parentShadowView;
397+
keyframe.parentTag = mutation.parentTag;
398398
react_native_assert(
399399
keyframe.finalMutationsForKeyFrame.size() == 1);
400-
keyframe.finalMutationsForKeyFrame[0].parentShadowView =
401-
mutation.parentShadowView;
400+
keyframe.finalMutationsForKeyFrame[0].parentTag =
401+
mutation.parentTag;
402402
}
403403
}
404404
}
@@ -426,7 +426,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
426426
mutation.oldChildShadowView.tag > 0) {
427427
executeMutationImmediately =
428428
ShadowViewMutation::RemoveMutation(
429-
mutation.parentShadowView,
429+
mutation.parentTag,
430430
keyframe.viewPrev,
431431
mutation.index);
432432
}
@@ -449,9 +449,9 @@ LayoutAnimationKeyFrameManager::pullTransaction(
449449
? mutation.newChildShadowView
450450
: viewStart);
451451
react_native_assert(viewFinal.tag > 0);
452-
ShadowView parent = mutation.parentShadowView;
452+
Tag parentTag = mutation.parentTag;
453453
react_native_assert(
454-
parent.tag > 0 ||
454+
parentTag > 0 ||
455455
mutation.type == ShadowViewMutation::Type::Update ||
456456
mutation.type == ShadowViewMutation::Type::Delete);
457457
Tag tag = viewStart.tag;
@@ -507,7 +507,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
507507
/* .finalMutationsForKeyFrame = */ {},
508508
/* .type = */ AnimationConfigurationType::Create,
509509
/* .tag = */ tag,
510-
/* .parentView = */ parent,
510+
/* .parentTag = */ parentTag,
511511
/* .viewStart = */ viewStart,
512512
/* .viewEnd = */ viewFinal,
513513
/* .viewPrev = */ baselineShadowView,
@@ -545,7 +545,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
545545
/* .finalMutationsForKeyFrame = */ {mutation},
546546
/* .type = */ AnimationConfigurationType::Update,
547547
/* .tag = */ tag,
548-
/* .parentView = */ parent,
548+
/* .parentTag = */ parentTag,
549549
/* .viewStart = */ viewStart,
550550
/* .viewEnd = */ viewFinal,
551551
/* .viewPrev = */ baselineShadowView,
@@ -631,7 +631,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
631631
/* .finalMutationsForKeyFrame */ {mutation, deleteMutation},
632632
/* .type */ AnimationConfigurationType::Delete,
633633
/* .tag */ tag,
634-
/* .parentView */ parent,
634+
/* .parentTag */ parentTag,
635635
/* .viewStart */ viewStart,
636636
/* .viewEnd */ viewFinal,
637637
/* .viewPrev */ baselineShadowView,
@@ -1184,19 +1184,17 @@ void LayoutAnimationKeyFrameManager::queueFinalMutationsForCompletedKeyFrame(
11841184
break;
11851185
case ShadowViewMutation::Type::Insert:
11861186
mutationsList.push_back(ShadowViewMutation::InsertMutation(
1187-
finalMutation.parentShadowView,
1187+
finalMutation.parentTag,
11881188
finalMutation.newChildShadowView,
11891189
finalMutation.index));
11901190
break;
11911191
case ShadowViewMutation::Type::Remove:
11921192
mutationsList.push_back(ShadowViewMutation::RemoveMutation(
1193-
finalMutation.parentShadowView, prev, finalMutation.index));
1193+
finalMutation.parentTag, prev, finalMutation.index));
11941194
break;
11951195
case ShadowViewMutation::Type::Update:
11961196
mutationsList.push_back(ShadowViewMutation::UpdateMutation(
1197-
prev,
1198-
finalMutation.newChildShadowView,
1199-
finalMutation.parentShadowView));
1197+
prev, finalMutation.newChildShadowView, finalMutation.parentTag));
12001198
break;
12011199
}
12021200
if (finalMutation.newChildShadowView.tag > 0) {
@@ -1221,7 +1219,7 @@ void LayoutAnimationKeyFrameManager::queueFinalMutationsForCompletedKeyFrame(
12211219
auto mutatedShadowView =
12221220
createInterpolatedShadowView(1, keyframe.viewStart, keyframe.viewEnd);
12231221
auto generatedPenultimateMutation = ShadowViewMutation::UpdateMutation(
1224-
keyframe.viewPrev, mutatedShadowView, keyframe.parentView);
1222+
keyframe.viewPrev, mutatedShadowView, keyframe.parentTag);
12251223
react_native_assert(
12261224
generatedPenultimateMutation.oldChildShadowView.tag > 0);
12271225
react_native_assert(
@@ -1232,7 +1230,7 @@ void LayoutAnimationKeyFrameManager::queueFinalMutationsForCompletedKeyFrame(
12321230
mutationsList.push_back(generatedPenultimateMutation);
12331231

12341232
auto generatedMutation = ShadowViewMutation::UpdateMutation(
1235-
mutatedShadowView, keyframe.viewEnd, keyframe.parentView);
1233+
mutatedShadowView, keyframe.viewEnd, keyframe.parentTag);
12361234
react_native_assert(generatedMutation.oldChildShadowView.tag > 0);
12371235
react_native_assert(generatedMutation.newChildShadowView.tag > 0);
12381236
PrintMutationInstruction(
@@ -1241,7 +1239,7 @@ void LayoutAnimationKeyFrameManager::queueFinalMutationsForCompletedKeyFrame(
12411239
mutationsList.push_back(generatedMutation);
12421240
} else {
12431241
auto mutation = ShadowViewMutation::UpdateMutation(
1244-
keyframe.viewPrev, keyframe.viewEnd, keyframe.parentView);
1242+
keyframe.viewPrev, keyframe.viewEnd, keyframe.parentTag);
12451243
PrintMutationInstruction(
12461244
logPrefix +
12471245
"Animation Complete: Queuing up Final Synthetic Mutation:",
@@ -1300,7 +1298,7 @@ void LayoutAnimationKeyFrameManager::
13001298

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

@@ -1405,7 +1403,7 @@ void LayoutAnimationKeyFrameManager::adjustDelayedMutationIndicesForMutation(
14051403

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

@@ -1519,8 +1517,8 @@ void LayoutAnimationKeyFrameManager::getAndEraseConflictingAnimations(
15191517
// we need to force deletion/removal to happen immediately.
15201518
bool conflicting = animatedKeyFrame.tag == baselineTag ||
15211519
(mutationIsCreateOrDelete &&
1522-
animatedKeyFrame.parentView.tag == baselineTag &&
1523-
animatedKeyFrame.parentView.tag != 0);
1520+
animatedKeyFrame.parentTag == baselineTag &&
1521+
animatedKeyFrame.parentTag != 0);
15241522

15251523
// Conflicting animation detected: if we're mutating a tag under
15261524
// animation, or deleting the parent of a tag under animation, or

packages/react-native/ReactCommon/react/renderer/animations/primitives.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct AnimationKeyFrame {
7070
// Tag representing the node being animated.
7171
Tag tag;
7272

73-
ShadowView parentView;
73+
Tag parentTag;
7474

7575
// ShadowView representing the start and end points of this animation.
7676
ShadowView viewStart;

packages/react-native/ReactCommon/react/renderer/animations/utils.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ static inline bool shouldFirstComeBeforeSecondRemovesOnly(
2020
// come first.
2121
return (lhs.type == ShadowViewMutation::Type::Remove &&
2222
lhs.type == rhs.type) &&
23-
(lhs.parentShadowView.tag == rhs.parentShadowView.tag) &&
24-
(lhs.index > rhs.index);
23+
(lhs.parentTag == rhs.parentTag) && (lhs.index > rhs.index);
2524
}
2625

2726
static inline void handleShouldFirstComeBeforeSecondRemovesOnly(
@@ -31,7 +30,7 @@ static inline void handleShouldFirstComeBeforeSecondRemovesOnly(
3130
ShadowViewMutation::List finalList;
3231
for (auto& mutation : list) {
3332
if (mutation.type == ShadowViewMutation::Type::Remove) {
34-
auto key = std::to_string(mutation.parentShadowView.tag);
33+
auto key = std::to_string(mutation.parentTag);
3534
removeMutationsByTag[key].push_back(mutation);
3635
} else {
3736
finalList.push_back(mutation);
@@ -104,7 +103,7 @@ static inline bool shouldFirstComeBeforeSecondMutation(
104103
// Make sure that removes on the same level are sorted - highest indices
105104
// must come first.
106105
if (lhs.type == ShadowViewMutation::Type::Remove &&
107-
lhs.parentShadowView.tag == rhs.parentShadowView.tag) {
106+
lhs.parentTag == rhs.parentTag) {
108107
if (lhs.index > rhs.index) {
109108
return true;
110109
} else {

0 commit comments

Comments
 (0)