Skip to content

Commit 56e9aa3

Browse files
javachefacebook-github-bot
authored andcommitted
Avoid emitting mountitems for default values
Summary: Noticed that we emit a large amount of (admittedly cheap) mountitems as part of node creation for values that are all zero (e.g. padding, overflowinset), which we can assume to be already initialised with these values on the native side. There's a further opportunity to do this for State as well, as ReactImageComponentState exports just empty maps to Java. Changelog: [Internal] Reviewed By: genkikondo Differential Revision: D36345402 fbshipit-source-id: 8d776ca124bdb9e1cd4de57a04e2785a9a0f918c
1 parent 8a8c33a commit 56e9aa3

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

ReactAndroid/src/main/java/com/facebook/react/fabric/jni/FabricMountingManager.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,20 +421,23 @@ void FabricMountingManager::executeMount(
421421
// are updated in the view. This is necessary to ensure that events
422422
// (resulting from layout changes) are dispatched with the correct
423423
// padding information.
424-
cppUpdatePaddingMountItems.push_back(
425-
CppMountItem::UpdatePaddingMountItem(
426-
mutation.newChildShadowView));
424+
if (newChildShadowView.layoutMetrics.contentInsets !=
425+
EdgeInsets::ZERO) {
426+
cppUpdatePaddingMountItems.push_back(
427+
CppMountItem::UpdatePaddingMountItem(newChildShadowView));
428+
}
427429

428430
// Layout
429431
cppUpdateLayoutMountItems.push_back(
430-
CppMountItem::UpdateLayoutMountItem(
431-
mutation.newChildShadowView));
432+
CppMountItem::UpdateLayoutMountItem(newChildShadowView));
432433

433434
// OverflowInset: This is the values indicating boundaries including
434435
// children of the current view. The layout of current view may not
435436
// change, and we separate this part from layout mount items to not
436437
// pack too much data there.
437-
if (useOverflowInset_) {
438+
if (useOverflowInset_ &&
439+
newChildShadowView.layoutMetrics.overflowInset !=
440+
EdgeInsets::ZERO) {
438441
cppUpdateOverflowInsetMountItems.push_back(
439442
CppMountItem::UpdateOverflowInsetMountItem(
440443
newChildShadowView));

ReactCommon/react/renderer/graphics/RectangleEdges.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ struct RectangleEdges {
3939
bool isUniform() const noexcept {
4040
return left == top && left == right && left == bottom;
4141
}
42+
43+
static RectangleEdges<T> const ZERO;
4244
};
4345

46+
template <typename T>
47+
constexpr RectangleEdges<T> const RectangleEdges<T>::ZERO = {};
48+
4449
template <typename T>
4550
RectangleEdges<T> operator+(
4651
RectangleEdges<T> const &lhs,

0 commit comments

Comments
 (0)