Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a39494512e761e266940e5d1853f38fc>>
* @generated SignedSource<<86390dbd6b2c57cb4f8cdd7cb73cc1f7>>
*/

/**
Expand Down Expand Up @@ -300,6 +300,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun enableNativeCSSParsing(): Boolean = accessor.enableNativeCSSParsing()

/**
* When enabled together with `enableAccumulatedUpdatesInRawPropsAndroid`, the Insert of a preallocated view only sends the difference between the props the view was preallocated with and the inserted props, instead of sending all props again on every Insert.
*/
@JvmStatic
public fun enablePreallocatedPropsDiffOnInsertAndroid(): Boolean = accessor.enablePreallocatedPropsDiffOnInsertAndroid()

/**
* Enables caching text layout artifacts for later reuse
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<cd1753241fa2f51c23cd4e01ffe3f18c>>
* @generated SignedSource<<3e939eebe846d12cab15905db8efba18>>
*/

/**
Expand Down Expand Up @@ -65,6 +65,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var enableMountingCoordinatorPullModelAndroidCache: Boolean? = null
private var enableMutationObserverByDefaultCache: Boolean? = null
private var enableNativeCSSParsingCache: Boolean? = null
private var enablePreallocatedPropsDiffOnInsertAndroidCache: Boolean? = null
private var enablePreparedTextLayoutCache: Boolean? = null
private var enablePropsUpdateReconciliationAndroidCache: Boolean? = null
private var enableResizeObserverByDefaultCache: Boolean? = null
Expand Down Expand Up @@ -515,6 +516,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun enablePreallocatedPropsDiffOnInsertAndroid(): Boolean {
var cached = enablePreallocatedPropsDiffOnInsertAndroidCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.enablePreallocatedPropsDiffOnInsertAndroid()
enablePreallocatedPropsDiffOnInsertAndroidCache = cached
}
return cached
}

override fun enablePreparedTextLayout(): Boolean {
var cached = enablePreparedTextLayoutCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<eb8737673aaec0b1eda6ae2ebc0b9970>>
* @generated SignedSource<<da34d40665437b2901de2ca5f0bee7c1>>
*/

/**
Expand Down Expand Up @@ -118,6 +118,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun enableNativeCSSParsing(): Boolean

@DoNotStrip @JvmStatic public external fun enablePreallocatedPropsDiffOnInsertAndroid(): Boolean

@DoNotStrip @JvmStatic public external fun enablePreparedTextLayout(): Boolean

@DoNotStrip @JvmStatic public external fun enablePropsUpdateReconciliationAndroid(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<890e204b6cf8afef481f64de44766edf>>
* @generated SignedSource<<0f4c074c11c564f05950eab73a8fd452>>
*/

/**
Expand Down Expand Up @@ -113,6 +113,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun enableNativeCSSParsing(): Boolean = false

override fun enablePreallocatedPropsDiffOnInsertAndroid(): Boolean = false

override fun enablePreparedTextLayout(): Boolean = false

override fun enablePropsUpdateReconciliationAndroid(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<9044f0df865ba9d7668f9ff391d21911>>
* @generated SignedSource<<013790bd2c3fa8b9ff03e8c5e924bf91>>
*/

/**
Expand Down Expand Up @@ -69,6 +69,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var enableMountingCoordinatorPullModelAndroidCache: Boolean? = null
private var enableMutationObserverByDefaultCache: Boolean? = null
private var enableNativeCSSParsingCache: Boolean? = null
private var enablePreallocatedPropsDiffOnInsertAndroidCache: Boolean? = null
private var enablePreparedTextLayoutCache: Boolean? = null
private var enablePropsUpdateReconciliationAndroidCache: Boolean? = null
private var enableResizeObserverByDefaultCache: Boolean? = null
Expand Down Expand Up @@ -564,6 +565,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}

override fun enablePreallocatedPropsDiffOnInsertAndroid(): Boolean {
var cached = enablePreallocatedPropsDiffOnInsertAndroidCache
if (cached == null) {
cached = currentProvider.enablePreallocatedPropsDiffOnInsertAndroid()
accessedFeatureFlags.add("enablePreallocatedPropsDiffOnInsertAndroid")
enablePreallocatedPropsDiffOnInsertAndroidCache = cached
}
return cached
}

override fun enablePreparedTextLayout(): Boolean {
var cached = enablePreparedTextLayoutCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<cfd99e53a077549124370e6bb123ba43>>
* @generated SignedSource<<6607c8678df2693c361f6d8091483662>>
*/

/**
Expand Down Expand Up @@ -113,6 +113,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun enableNativeCSSParsing(): Boolean

@DoNotStrip public fun enablePreallocatedPropsDiffOnInsertAndroid(): Boolean

@DoNotStrip public fun enablePreparedTextLayout(): Boolean

@DoNotStrip public fun enablePropsUpdateReconciliationAndroid(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ FabricMountingManager::~FabricMountingManager() {
void FabricMountingManager::onSurfaceStart(SurfaceId surfaceId) {
std::lock_guard lock(allocatedViewsMutex_);
allocatedViewRegistry_.emplace(
surfaceId, std::unordered_set<Tag>({surfaceId}));
surfaceId, std::unordered_map<Tag, Props::Shared>{{surfaceId, nullptr}});
}

void FabricMountingManager::onSurfaceStop(SurfaceId surfaceId) {
Expand Down Expand Up @@ -311,6 +311,11 @@ inline float scale(Float value, Float pointScaleFactor) {
return result;
}

bool shouldDiffInsertPropsAgainstPreallocatedProps() {
return ReactNativeFeatureFlags::enableAccumulatedUpdatesInRawPropsAndroid() &&
ReactNativeFeatureFlags::enablePreallocatedPropsDiffOnInsertAndroid();
}

jni::local_ref<jobject> getProps(
const ShadowView& oldShadowView,
const ShadowView& newShadowView) {
Expand Down Expand Up @@ -609,12 +614,12 @@ void FabricMountingManager::executeMount(
std::lock_guard allocatedViewsLock(allocatedViewsMutex_);

auto allocatedViewsIterator = allocatedViewRegistry_.find(surfaceId);
auto defaultAllocatedViews = std::unordered_set<Tag>{};
auto defaultAllocatedViews = std::unordered_map<Tag, Props::Shared>{};
// Do not remove `defaultAllocatedViews` or initialize
// `std::unordered_set<Tag>{}` inline in below ternary expression - if falsy
// operand is a value type, the compiler will decide the expression to be a
// value type, an unnecessary (sometimes expensive) copy will happen as a
// result.
// `std::unordered_map<Tag, Props::Shared>{}` inline in below ternary
// expression - if falsy operand is a value type, the compiler will decide
// the expression to be a value type, an unnecessary (sometimes expensive)
// copy will happen as a result.
auto& allocatedViewTags =
allocatedViewsIterator != allocatedViewRegistry_.end()
? allocatedViewsIterator->second
Expand All @@ -640,7 +645,7 @@ void FabricMountingManager::executeMount(
if (shouldCreateView) {
cppCommonMountItems.push_back(
CppMountItem::CreateMountItem(newChildShadowView));
allocatedViewTags.insert(newChildShadowView.tag);
allocatedViewTags.emplace(newChildShadowView.tag, nullptr);
}
break;
}
Expand Down Expand Up @@ -734,19 +739,34 @@ void FabricMountingManager::executeMount(
CppMountItem::InsertMountItem(
parentTag, newChildShadowView, index));

bool shouldCreateView =
!allocatedViewTags.contains(newChildShadowView.tag);
auto allocatedView = allocatedViewTags.find(newChildShadowView.tag);
bool shouldCreateView = allocatedView == allocatedViewTags.end();
if (ReactNativeFeatureFlags::
enableAccumulatedUpdatesInRawPropsAndroid()) {
if (shouldCreateView) {
LOG(ERROR) << "Emitting insert for unallocated view "
<< newChildShadowView.tag;
}
(maintainMutationOrder ? cppCommonMountItems
: cppUpdatePropsMountItems)
.push_back(
CppMountItem::UpdatePropsMountItem(
{}, newChildShadowView));
if (shouldCreateView ||
!shouldDiffInsertPropsAgainstPreallocatedProps()) {
(maintainMutationOrder ? cppCommonMountItems
: cppUpdatePropsMountItems)
.push_back(
CppMountItem::UpdatePropsMountItem(
{}, newChildShadowView));
} else if (auto& preallocatedProps = allocatedView->second;
preallocatedProps != nullptr) {
if (preallocatedProps != newChildShadowView.props) {
auto preallocatedShadowView = newChildShadowView;
preallocatedShadowView.props = preallocatedProps;
(maintainMutationOrder ? cppCommonMountItems
: cppUpdatePropsMountItems)
.push_back(
CppMountItem::UpdatePropsMountItem(
preallocatedShadowView, newChildShadowView));
}
preallocatedProps = nullptr;
}
} else {
if (shouldCreateView) {
LOG(ERROR) << "Emitting insert for unallocated view "
Expand Down Expand Up @@ -1107,8 +1127,10 @@ void FabricMountingManager::preallocateShadowView(
if (allocatedViewsIterator == allocatedViewRegistry_.end()) {
return;
}
const auto [_, inserted] =
allocatedViewsIterator->second.insert(shadowView.tag);
const auto [_, inserted] = allocatedViewsIterator->second.emplace(
shadowView.tag,
shouldDiffInsertPropsAgainstPreallocatedProps() ? shadowView.props
: nullptr);
if (!inserted) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

#include <mutex>
#include <unordered_map>
#include <unordered_set>

#include <fbjni/fbjni.h>
#include <react/fabric/JFabricUIManager.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/uimanager/primitives.h>

namespace facebook::react {
Expand Down Expand Up @@ -109,7 +109,12 @@ class FabricMountingManager final {
*/
std::vector<ShadowView> preallocatedViewsQueue_{};

std::unordered_map<SurfaceId, std::unordered_set<Tag>> allocatedViewRegistry_{};
/*
* Allocated tags per surface. With enablePreallocatedPropsDiffOnInsertAndroid
* a preallocated tag maps to the props it was preallocated with until its
* first Insert; every other tag maps to nullptr.
*/
std::unordered_map<SurfaceId, std::unordered_map<Tag, Props::Shared>> allocatedViewRegistry_{};
std::recursive_mutex allocatedViewsMutex_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<e6f56d60147d5c08e0b38549b9956e52>>
* @generated SignedSource<<dad8d48d93f01fc5ec68f70dbd9a9e73>>
*/

/**
Expand Down Expand Up @@ -309,6 +309,12 @@ class ReactNativeFeatureFlagsJavaProvider
return method(javaProvider_);
}

bool enablePreallocatedPropsDiffOnInsertAndroid() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enablePreallocatedPropsDiffOnInsertAndroid");
return method(javaProvider_);
}

bool enablePreparedTextLayout() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enablePreparedTextLayout");
Expand Down Expand Up @@ -802,6 +808,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableNativeCSSParsing(
return ReactNativeFeatureFlags::enableNativeCSSParsing();
}

bool JReactNativeFeatureFlagsCxxInterop::enablePreallocatedPropsDiffOnInsertAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enablePreallocatedPropsDiffOnInsertAndroid();
}

bool JReactNativeFeatureFlagsCxxInterop::enablePreparedTextLayout(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enablePreparedTextLayout();
Expand Down Expand Up @@ -1188,6 +1199,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"enableNativeCSSParsing",
JReactNativeFeatureFlagsCxxInterop::enableNativeCSSParsing),
makeNativeMethod(
"enablePreallocatedPropsDiffOnInsertAndroid",
JReactNativeFeatureFlagsCxxInterop::enablePreallocatedPropsDiffOnInsertAndroid),
makeNativeMethod(
"enablePreparedTextLayout",
JReactNativeFeatureFlagsCxxInterop::enablePreparedTextLayout),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<25d66101785e737822e86d218789912d>>
* @generated SignedSource<<7a9a9c1938c3e01f589e05fffe349ad3>>
*/

/**
Expand Down Expand Up @@ -165,6 +165,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool enableNativeCSSParsing(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enablePreallocatedPropsDiffOnInsertAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enablePreparedTextLayout(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<8b8b80ac3744a205b20cfd0627856fba>>
* @generated SignedSource<<8b23b6ea5f2d377f8126adffd753dae7>>
*/

/**
Expand Down Expand Up @@ -206,6 +206,10 @@ bool ReactNativeFeatureFlags::enableNativeCSSParsing() {
return getAccessor().enableNativeCSSParsing();
}

bool ReactNativeFeatureFlags::enablePreallocatedPropsDiffOnInsertAndroid() {
return getAccessor().enablePreallocatedPropsDiffOnInsertAndroid();
}

bool ReactNativeFeatureFlags::enablePreparedTextLayout() {
return getAccessor().enablePreparedTextLayout();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<4c93a39dd2a8ee5ba24f3f8bc99ac1ae>>
* @generated SignedSource<<aef7d6ac25fdeb2423ebf4a2a9ac6f2e>>
*/

/**
Expand Down Expand Up @@ -266,6 +266,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool enableNativeCSSParsing();

/**
* When enabled together with `enableAccumulatedUpdatesInRawPropsAndroid`, the Insert of a preallocated view only sends the difference between the props the view was preallocated with and the inserted props, instead of sending all props again on every Insert.
*/
RN_EXPORT static bool enablePreallocatedPropsDiffOnInsertAndroid();

/**
* Enables caching text layout artifacts for later reuse
*/
Expand Down
Loading
Loading