From 56e9aa369f5c13af38cf80ba47e9eb29d835ec89 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Wed, 18 May 2022 05:44:11 -0700 Subject: [PATCH] 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 --- .../react/fabric/jni/FabricMountingManager.cpp | 15 +++++++++------ .../react/renderer/graphics/RectangleEdges.h | 5 +++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/FabricMountingManager.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/FabricMountingManager.cpp index d1991f70ba3..a917a2011ca 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/FabricMountingManager.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/FabricMountingManager.cpp @@ -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)); diff --git a/ReactCommon/react/renderer/graphics/RectangleEdges.h b/ReactCommon/react/renderer/graphics/RectangleEdges.h index 65f6f5990e3..2deae70b306 100644 --- a/ReactCommon/react/renderer/graphics/RectangleEdges.h +++ b/ReactCommon/react/renderer/graphics/RectangleEdges.h @@ -39,8 +39,13 @@ struct RectangleEdges { bool isUniform() const noexcept { return left == top && left == right && left == bottom; } + + static RectangleEdges const ZERO; }; +template +constexpr RectangleEdges const RectangleEdges::ZERO = {}; + template RectangleEdges operator+( RectangleEdges const &lhs,