Skip to content

Commit

Permalink
Avoid emitting mountitems for default values
Browse files Browse the repository at this point in the history
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
  • Loading branch information
javache authored and facebook-github-bot committed May 18, 2022
1 parent 8a8c33a commit 56e9aa3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,20 +421,23 @@ void FabricMountingManager::executeMount(
// are updated in the view. This is necessary to ensure that events
// (resulting from layout changes) are dispatched with the correct
// padding information.
cppUpdatePaddingMountItems.push_back(
CppMountItem::UpdatePaddingMountItem(
mutation.newChildShadowView));
if (newChildShadowView.layoutMetrics.contentInsets !=
EdgeInsets::ZERO) {
cppUpdatePaddingMountItems.push_back(
CppMountItem::UpdatePaddingMountItem(newChildShadowView));
}

// Layout
cppUpdateLayoutMountItems.push_back(
CppMountItem::UpdateLayoutMountItem(
mutation.newChildShadowView));
CppMountItem::UpdateLayoutMountItem(newChildShadowView));

// OverflowInset: This is the values indicating boundaries including
// children of the current view. The layout of current view may not
// change, and we separate this part from layout mount items to not
// pack too much data there.
if (useOverflowInset_) {
if (useOverflowInset_ &&
newChildShadowView.layoutMetrics.overflowInset !=
EdgeInsets::ZERO) {
cppUpdateOverflowInsetMountItems.push_back(
CppMountItem::UpdateOverflowInsetMountItem(
newChildShadowView));
Expand Down
5 changes: 5 additions & 0 deletions ReactCommon/react/renderer/graphics/RectangleEdges.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ struct RectangleEdges {
bool isUniform() const noexcept {
return left == top && left == right && left == bottom;
}

static RectangleEdges<T> const ZERO;
};

template <typename T>
constexpr RectangleEdges<T> const RectangleEdges<T>::ZERO = {};

template <typename T>
RectangleEdges<T> operator+(
RectangleEdges<T> const &lhs,
Expand Down

0 comments on commit 56e9aa3

Please sign in to comment.