Ship useUnorderedMapInDifferentiator (#56918)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56918

changelog: [internal]

the experiment was neutral, let's ship it to simplify code

Reviewed By: javache

Differential Revision: D105943424

fbshipit-source-id: 3ff2ed1dbcb85f640305c4fcb2485db0a8a312fc
This commit is contained in:
Samuel Susla authored and meta-codesync[bot] committed 2026-05-22 08:57:50 -07:00
1 parent 6aa7e35ec3
commit 58012fb445
33 files changed
+51 -660

No files matched your search

@@ -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<<8b35aa70eea734a8bfcbb7bd651ba8e2>>
* @generated SignedSource<<fb433838ff712ffa7b045065a35723f2>>
*/
/**
@@ -540,12 +540,6 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun useTurboModuleInterop(): Boolean = accessor.useTurboModuleInterop()
/**
* Use std::unordered_map instead of TinyMap in the Differentiator for improved lookup performance.
*/
@JvmStatic
public fun useUnorderedMapInDifferentiator(): Boolean = accessor.useUnorderedMapInDifferentiator()
/**
* Outset the culling context frame with the provided ratio. The culling context frame size will be outset by width * ratio on the left and right, and height * ratio on the top and bottom.
*/
@@ -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<<494ed85c58f80b4feb6fb9b83fe7a27e>>
* @generated SignedSource<<1ac9ff65ae410a6b1afa6c92c2e9a86b>>
*/
/**
@@ -105,7 +105,6 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var useSharedAnimatedBackendCache: Boolean? = null
private var useTraitHiddenOnAndroidCache: Boolean? = null
private var useTurboModuleInteropCache: Boolean? = null
private var useUnorderedMapInDifferentiatorCache: Boolean? = null
private var viewCullingOutsetRatioCache: Double? = null
private var viewTransitionEnabledCache: Boolean? = null
private var viewTransitionUseHardwareBitmapAndroidCache: Boolean? = null
@@ -876,15 +875,6 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}
override fun useUnorderedMapInDifferentiator(): Boolean {
var cached = useUnorderedMapInDifferentiatorCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.useUnorderedMapInDifferentiator()
useUnorderedMapInDifferentiatorCache = cached
}
return cached
}
override fun viewCullingOutsetRatio(): Double {
var cached = viewCullingOutsetRatioCache
if (cached == null) {
@@ -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<<16ca9a4b47da90ea71300eb37287e28b>>
* @generated SignedSource<<b63f95bdb6536ae1623bb4a69f2c4940>>
*/
/**
@@ -198,8 +198,6 @@ public object ReactNativeFeatureFlagsCxxInterop {
@DoNotStrip @JvmStatic public external fun useTurboModuleInterop(): Boolean
@DoNotStrip @JvmStatic public external fun useUnorderedMapInDifferentiator(): Boolean
@DoNotStrip @JvmStatic public external fun viewCullingOutsetRatio(): Double
@DoNotStrip @JvmStatic public external fun viewTransitionEnabled(): Boolean
@@ -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<<10e6516b3c9cf53ae2e48c8b8cd51033>>
* @generated SignedSource<<960de240ad648acc1dca10a80e2bf8a5>>
*/
/**
@@ -193,8 +193,6 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
override fun useTurboModuleInterop(): Boolean = false
override fun useUnorderedMapInDifferentiator(): Boolean = false
override fun viewCullingOutsetRatio(): Double = 0.0
override fun viewTransitionEnabled(): Boolean = false
@@ -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<<441fe8be28d4521e1fe9fe7b87b74cf2>>
* @generated SignedSource<<39d4538c638e38cbd1655064edc74761>>
*/
/**
@@ -109,7 +109,6 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var useSharedAnimatedBackendCache: Boolean? = null
private var useTraitHiddenOnAndroidCache: Boolean? = null
private var useTurboModuleInteropCache: Boolean? = null
private var useUnorderedMapInDifferentiatorCache: Boolean? = null
private var viewCullingOutsetRatioCache: Double? = null
private var viewTransitionEnabledCache: Boolean? = null
private var viewTransitionUseHardwareBitmapAndroidCache: Boolean? = null
@@ -965,16 +964,6 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}
override fun useUnorderedMapInDifferentiator(): Boolean {
var cached = useUnorderedMapInDifferentiatorCache
if (cached == null) {
cached = currentProvider.useUnorderedMapInDifferentiator()
accessedFeatureFlags.add("useUnorderedMapInDifferentiator")
useUnorderedMapInDifferentiatorCache = cached
}
return cached
}
override fun viewCullingOutsetRatio(): Double {
var cached = viewCullingOutsetRatioCache
if (cached == null) {
@@ -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<<972dbaef144818484bafff334cf97ef2>>
* @generated SignedSource<<4fa46d585a2fe3515557bf06f0e1189f>>
*/
/**
@@ -193,8 +193,6 @@ public interface ReactNativeFeatureFlagsProvider {
@DoNotStrip public fun useTurboModuleInterop(): Boolean
@DoNotStrip public fun useUnorderedMapInDifferentiator(): Boolean
@DoNotStrip public fun viewCullingOutsetRatio(): Double
@DoNotStrip public fun viewTransitionEnabled(): Boolean
@@ -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<<bb79417efb0f63b2717ea8873b72da88>>
* @generated SignedSource<<e289807a5e54422b373acc929ce31e10>>
*/
/**
@@ -549,12 +549,6 @@ class ReactNativeFeatureFlagsJavaProvider
return method(javaProvider_);
}
bool useUnorderedMapInDifferentiator() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useUnorderedMapInDifferentiator");
return method(javaProvider_);
}
double viewCullingOutsetRatio() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jdouble()>("viewCullingOutsetRatio");
@@ -1008,11 +1002,6 @@ bool JReactNativeFeatureFlagsCxxInterop::useTurboModuleInterop(
return ReactNativeFeatureFlags::useTurboModuleInterop();
}
bool JReactNativeFeatureFlagsCxxInterop::useUnorderedMapInDifferentiator(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::useUnorderedMapInDifferentiator();
}
double JReactNativeFeatureFlagsCxxInterop::viewCullingOutsetRatio(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::viewCullingOutsetRatio();
@@ -1319,9 +1308,6 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"useTurboModuleInterop",
JReactNativeFeatureFlagsCxxInterop::useTurboModuleInterop),
makeNativeMethod(
"useUnorderedMapInDifferentiator",
JReactNativeFeatureFlagsCxxInterop::useUnorderedMapInDifferentiator),
makeNativeMethod(
"viewCullingOutsetRatio",
JReactNativeFeatureFlagsCxxInterop::viewCullingOutsetRatio),
@@ -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<<3007628255a078dafc01eb16b3d55fbe>>
* @generated SignedSource<<8e51c38f988854dd63291df26a78326e>>
*/
/**
@@ -285,9 +285,6 @@ class JReactNativeFeatureFlagsCxxInterop
static bool useTurboModuleInterop(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
static bool useUnorderedMapInDifferentiator(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
static double viewCullingOutsetRatio(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
@@ -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<<5c308b51617953c21d3ae60dc8c530bb>>
* @generated SignedSource<<a6fff34229abbd9beaa08bf39b379610>>
*/
/**
@@ -366,10 +366,6 @@ bool ReactNativeFeatureFlags::useTurboModuleInterop() {
return getAccessor().useTurboModuleInterop();
}
bool ReactNativeFeatureFlags::useUnorderedMapInDifferentiator() {
return getAccessor().useUnorderedMapInDifferentiator();
}
double ReactNativeFeatureFlags::viewCullingOutsetRatio() {
return getAccessor().viewCullingOutsetRatio();
}
@@ -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<<ac9244d8e244e6ee81a39b6c6d3fbf5e>>
* @generated SignedSource<<6508c960d2b27f479ecb40056d5c7997>>
*/
/**
@@ -464,11 +464,6 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool useTurboModuleInterop();
/**
* Use std::unordered_map instead of TinyMap in the Differentiator for improved lookup performance.
*/
RN_EXPORT static bool useUnorderedMapInDifferentiator();
/**
* Outset the culling context frame with the provided ratio. The culling context frame size will be outset by width * ratio on the left and right, and height * ratio on the top and bottom.
*/
@@ -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<<b6e609ac672edc9dade5662cf5890fe6>>
* @generated SignedSource<<741c9218697690640831ca2e47090938>>
*/
/**
@@ -1559,24 +1559,6 @@ bool ReactNativeFeatureFlagsAccessor::useTurboModuleInterop() {
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::useUnorderedMapInDifferentiator() {
auto flagValue = useUnorderedMapInDifferentiator_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(85, "useUnorderedMapInDifferentiator");
flagValue = currentProvider_->useUnorderedMapInDifferentiator();
useUnorderedMapInDifferentiator_ = flagValue;
}
return flagValue.value();
}
double ReactNativeFeatureFlagsAccessor::viewCullingOutsetRatio() {
auto flagValue = viewCullingOutsetRatio_.load();
@@ -1586,7 +1568,7 @@ double ReactNativeFeatureFlagsAccessor::viewCullingOutsetRatio() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(86, "viewCullingOutsetRatio");
markFlagAsAccessed(85, "viewCullingOutsetRatio");
flagValue = currentProvider_->viewCullingOutsetRatio();
viewCullingOutsetRatio_ = flagValue;
@@ -1604,7 +1586,7 @@ bool ReactNativeFeatureFlagsAccessor::viewTransitionEnabled() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(87, "viewTransitionEnabled");
markFlagAsAccessed(86, "viewTransitionEnabled");
flagValue = currentProvider_->viewTransitionEnabled();
viewTransitionEnabled_ = flagValue;
@@ -1622,7 +1604,7 @@ bool ReactNativeFeatureFlagsAccessor::viewTransitionUseHardwareBitmapAndroid() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(88, "viewTransitionUseHardwareBitmapAndroid");
markFlagAsAccessed(87, "viewTransitionUseHardwareBitmapAndroid");
flagValue = currentProvider_->viewTransitionUseHardwareBitmapAndroid();
viewTransitionUseHardwareBitmapAndroid_ = flagValue;
@@ -1640,7 +1622,7 @@ double ReactNativeFeatureFlagsAccessor::virtualViewPrerenderRatio() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(89, "virtualViewPrerenderRatio");
markFlagAsAccessed(88, "virtualViewPrerenderRatio");
flagValue = currentProvider_->virtualViewPrerenderRatio();
virtualViewPrerenderRatio_ = flagValue;
@@ -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<<fda7bc739026295c2acd473ad6786942>>
* @generated SignedSource<<1bab95e3659f13124ff8f159f38fc39f>>
*/
/**
@@ -117,7 +117,6 @@ class ReactNativeFeatureFlagsAccessor {
bool useSharedAnimatedBackend();
bool useTraitHiddenOnAndroid();
bool useTurboModuleInterop();
bool useUnorderedMapInDifferentiator();
double viewCullingOutsetRatio();
bool viewTransitionEnabled();
bool viewTransitionUseHardwareBitmapAndroid();
@@ -133,7 +132,7 @@ class ReactNativeFeatureFlagsAccessor {
std::unique_ptr<ReactNativeFeatureFlagsProvider> currentProvider_;
bool wasOverridden_;
std::array<std::atomic<const char*>, 90> accessedFeatureFlags_;
std::array<std::atomic<const char*>, 89> accessedFeatureFlags_;
std::atomic<std::optional<bool>> commonTestFlag_;
std::atomic<std::optional<bool>> cdpInteractionMetricsEnabled_;
@@ -220,7 +219,6 @@ class ReactNativeFeatureFlagsAccessor {
std::atomic<std::optional<bool>> useSharedAnimatedBackend_;
std::atomic<std::optional<bool>> useTraitHiddenOnAndroid_;
std::atomic<std::optional<bool>> useTurboModuleInterop_;
std::atomic<std::optional<bool>> useUnorderedMapInDifferentiator_;
std::atomic<std::optional<double>> viewCullingOutsetRatio_;
std::atomic<std::optional<bool>> viewTransitionEnabled_;
std::atomic<std::optional<bool>> viewTransitionUseHardwareBitmapAndroid_;
@@ -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<<dbcd4c009540936ebc7b5b0788bf7b73>>
* @generated SignedSource<<37d25a3c42a4bc9dde1665aaacd1acbd>>
*/
/**
@@ -367,10 +367,6 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider {
return false;
}
bool useUnorderedMapInDifferentiator() override {
return false;
}
double viewCullingOutsetRatio() override {
return 0.0;
}
@@ -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<<ae76472d710702e636b577bb6d125bc3>>
* @generated SignedSource<<eab88ff064856e8ad3d284f73155b3e4>>
*/
/**
@@ -810,15 +810,6 @@ class ReactNativeFeatureFlagsDynamicProvider : public ReactNativeFeatureFlagsDef
return ReactNativeFeatureFlagsDefaults::useTurboModuleInterop();
}
bool useUnorderedMapInDifferentiator() override {
auto value = values_["useUnorderedMapInDifferentiator"];
if (!value.isNull()) {
return value.getBool();
}
return ReactNativeFeatureFlagsDefaults::useUnorderedMapInDifferentiator();
}
double viewCullingOutsetRatio() override {
auto value = values_["viewCullingOutsetRatio"];
if (!value.isNull()) {
@@ -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<<584f593b7ca1ea2ab72b7de7afd6b70d>>
* @generated SignedSource<<f5abdc61246d15927faab8529da3b6c5>>
*/
/**
@@ -110,7 +110,6 @@ class ReactNativeFeatureFlagsProvider {
virtual bool useSharedAnimatedBackend() = 0;
virtual bool useTraitHiddenOnAndroid() = 0;
virtual bool useTurboModuleInterop() = 0;
virtual bool useUnorderedMapInDifferentiator() = 0;
virtual double viewCullingOutsetRatio() = 0;
virtual bool viewTransitionEnabled() = 0;
virtual bool viewTransitionUseHardwareBitmapAndroid() = 0;
@@ -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<<086755643a71f66d1cd023fd36d74fd6>>
* @generated SignedSource<<c19602f633bf0881596620b2c3e28ea5>>
*/
/**
@@ -469,11 +469,6 @@ bool NativeReactNativeFeatureFlags::useTurboModuleInterop(
return ReactNativeFeatureFlags::useTurboModuleInterop();
}
bool NativeReactNativeFeatureFlags::useUnorderedMapInDifferentiator(
jsi::Runtime& /*runtime*/) {
return ReactNativeFeatureFlags::useUnorderedMapInDifferentiator();
}
double NativeReactNativeFeatureFlags::viewCullingOutsetRatio(
jsi::Runtime& /*runtime*/) {
return ReactNativeFeatureFlags::viewCullingOutsetRatio();
@@ -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<<0eb12f4ad26d7d2b558057e3a6bf2de7>>
* @generated SignedSource<<0aa224e971f7ed80b6194c426d59653a>>
*/
/**
@@ -206,8 +206,6 @@ class NativeReactNativeFeatureFlags
bool useTurboModuleInterop(jsi::Runtime& runtime);
bool useUnorderedMapInDifferentiator(jsi::Runtime& runtime);
double viewCullingOutsetRatio(jsi::Runtime& runtime);
bool viewTransitionEnabled(jsi::Runtime& runtime);
@@ -11,8 +11,8 @@
#include <react/debug/react_native_assert.h>
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <algorithm>
#include <unordered_map>
#include "internal/CullingContext.h"
#include "internal/DiffMap.h"
#include "internal/ShadowViewNodePair.h"
#include "internal/sliceChildShadowNodeViewPairs.h"
@@ -58,7 +58,9 @@ static std::ostream& operator<<(
#ifdef DEBUG_LOGS_DIFFER
template <typename KeyT, typename ValueT>
static std::ostream& operator<<(std::ostream& out, DiffMap<KeyT, ValueT>& map) {
static std::ostream& operator<<(
std::ostream& out,
const std::unordered_map<KeyT, ValueT>& map) {
auto it = map.begin();
if (it != map.end()) {
out << *it->second;
@@ -143,7 +145,7 @@ struct OrderedMutationInstructionContainer {
static void updateMatchedPairSubtrees(
ViewNodePairScope& scope,
OrderedMutationInstructionContainer& mutationContainer,
DiffMap<Tag, ShadowViewNodePair*>& newRemainingPairs,
std::unordered_map<Tag, ShadowViewNodePair*>& newRemainingPairs,
std::vector<ShadowViewNodePair*>& oldChildPairs,
Tag parentTag,
const ShadowViewNodePair& oldPair,
@@ -164,11 +166,11 @@ static void calculateShadowViewMutationsFlattener(
ReparentMode reparentMode,
OrderedMutationInstructionContainer& mutationContainer,
Tag parentTag,
DiffMap<Tag, ShadowViewNodePair*>& unvisitedOtherNodes,
std::unordered_map<Tag, ShadowViewNodePair*>& unvisitedOtherNodes,
const ShadowViewNodePair& node,
Tag parentTagForUpdate,
DiffMap<Tag, ShadowViewNodePair*>* parentSubVisitedOtherNewNodes,
DiffMap<Tag, ShadowViewNodePair*>* parentSubVisitedOtherOldNodes,
std::unordered_map<Tag, ShadowViewNodePair*>* parentSubVisitedOtherNewNodes,
std::unordered_map<Tag, ShadowViewNodePair*>* parentSubVisitedOtherOldNodes,
const CullingContext& cullingContextForUnvisitedOtherNodes,
const CullingContext& cullingContext);
@@ -183,7 +185,7 @@ static void calculateShadowViewMutationsFlattener(
static void updateMatchedPairSubtrees(
ViewNodePairScope& scope,
OrderedMutationInstructionContainer& mutationContainer,
DiffMap<Tag, ShadowViewNodePair*>& newRemainingPairs,
std::unordered_map<Tag, ShadowViewNodePair*>& newRemainingPairs,
std::vector<ShadowViewNodePair*>& oldChildPairs,
Tag parentTag,
const ShadowViewNodePair& oldPair,
@@ -239,8 +241,8 @@ static void updateMatchedPairSubtrees(
// interwoven with children from other nodes, etc.
auto oldFlattenedNodes = sliceChildShadowNodeViewPairsFromViewNodePair(
oldPair, scope, true, oldCullingContextCopy);
auto unvisitedOldChildPairs =
DiffMap<Tag, ShadowViewNodePair*>(oldFlattenedNodes.size());
std::unordered_map<Tag, ShadowViewNodePair*> unvisitedOldChildPairs;
unvisitedOldChildPairs.reserve(oldFlattenedNodes.size());
for (size_t i = 0, j = 0;
i < oldChildPairs.size() && j < oldFlattenedNodes.size();
i++) {
@@ -423,11 +425,11 @@ static void calculateShadowViewMutationsFlattener(
ReparentMode reparentMode,
OrderedMutationInstructionContainer& mutationContainer,
Tag parentTag,
DiffMap<Tag, ShadowViewNodePair*>& unvisitedOtherNodes,
std::unordered_map<Tag, ShadowViewNodePair*>& unvisitedOtherNodes,
const ShadowViewNodePair& node,
Tag parentTagForUpdate,
DiffMap<Tag, ShadowViewNodePair*>* parentSubVisitedOtherNewNodes,
DiffMap<Tag, ShadowViewNodePair*>* parentSubVisitedOtherOldNodes,
std::unordered_map<Tag, ShadowViewNodePair*>* parentSubVisitedOtherNewNodes,
std::unordered_map<Tag, ShadowViewNodePair*>* parentSubVisitedOtherOldNodes,
const CullingContext& cullingContextForUnvisitedOtherNodes,
const CullingContext& cullingContext) {
// Step 1: iterate through entire tree
@@ -446,8 +448,8 @@ static void calculateShadowViewMutationsFlattener(
// Views in other tree that are visited by sub-flattening or
// sub-unflattening
DiffMap<Tag, ShadowViewNodePair*> subVisitedOtherNewNodes{};
DiffMap<Tag, ShadowViewNodePair*> subVisitedOtherOldNodes{};
std::unordered_map<Tag, ShadowViewNodePair*> subVisitedOtherNewNodes{};
std::unordered_map<Tag, ShadowViewNodePair*> subVisitedOtherOldNodes{};
auto subVisitedNewMap =
(parentSubVisitedOtherNewNodes != nullptr ? parentSubVisitedOtherNewNodes
: &subVisitedOtherNewNodes);
@@ -456,8 +458,9 @@ static void calculateShadowViewMutationsFlattener(
: &subVisitedOtherOldNodes);
// Candidates for full tree creation or deletion at the end of this function
auto deletionCreationCandidatePairs =
DiffMap<Tag, const ShadowViewNodePair*>(treeChildren.size());
std::unordered_map<Tag, const ShadowViewNodePair*>
deletionCreationCandidatePairs;
deletionCreationCandidatePairs.reserve(treeChildren.size());
for (size_t index = 0;
index < treeChildren.size() && index < treeChildren.size();
@@ -700,8 +703,9 @@ static void calculateShadowViewMutationsFlattener(
? adjustedNewCullingContext
: adjustedOldCullingContext);
// Construct unvisited nodes map
auto unvisitedRecursiveChildPairs =
DiffMap<Tag, ShadowViewNodePair*>(flattenedNodes.size());
std::unordered_map<Tag, ShadowViewNodePair*>
unvisitedRecursiveChildPairs;
unvisitedRecursiveChildPairs.reserve(flattenedNodes.size());
for (auto& flattenedNode : flattenedNodes) {
auto& newChild = *flattenedNode;
@@ -1056,9 +1060,11 @@ static void calculateShadowViewMutations(
// Greedy Stage 4 algorithm.
// Collect map of tags in the new list
auto remainingCount = newChildPairs.size() - lastIndexAfterFirstStage;
auto newRemainingPairs = DiffMap<Tag, ShadowViewNodePair*>(remainingCount);
auto newInsertedPairs = DiffMap<Tag, ShadowViewNodePair*>(remainingCount);
auto deletionCandidatePairs = DiffMap<Tag, const ShadowViewNodePair*>{};
std::unordered_map<Tag, ShadowViewNodePair*> newRemainingPairs;
newRemainingPairs.reserve(remainingCount);
std::unordered_map<Tag, ShadowViewNodePair*> newInsertedPairs;
newInsertedPairs.reserve(remainingCount);
std::unordered_map<Tag, const ShadowViewNodePair*> deletionCandidatePairs{};
for (index = lastIndexAfterFirstStage; index < newChildPairs.size();
index++) {
auto& newChildPair = *newChildPairs[index];
@@ -1,170 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <optional>
#include <unordered_map>
#include "TinyMap.h"
namespace facebook::react {
/**
* A facade that delegates to either TinyMap or std::unordered_map based on
* the useUnorderedMapInDifferentiator feature flag. This allows safe rollout
* of the unordered_map change in the Differentiator.
*
* Exposes a subset of the std::unordered_map interface used by the
* Differentiator: find, insert, erase, begin, end, and range-for.
*
* The Iterator returns const references because it uses a cached copy
* internally (the two backends have different pair types). The Differentiator
* only reads through iterators, never writes.
*/
template <typename KeyT, typename ValueT>
class DiffMap final {
public:
using Pair = std::pair<KeyT, ValueT>;
class Iterator {
public:
const Pair &operator*() const
{
syncCached();
return cached_;
}
const Pair *operator->() const
{
syncCached();
return &cached_;
}
Iterator &operator++()
{
if (useUnorderedMap_) {
++umIt_;
} else {
++tinyIt_;
}
dirty_ = true;
return *this;
}
bool operator==(const Iterator &other) const
{
if (useUnorderedMap_) {
return umIt_ == other.umIt_;
}
return tinyIt_ == other.tinyIt_;
}
bool operator!=(const Iterator &other) const
{
return !(*this == other);
}
private:
friend class DiffMap;
void syncCached() const
{
if (!dirty_) {
return;
}
if (useUnorderedMap_) {
cached_ = {umIt_->first, umIt_->second};
} else {
cached_ = {tinyIt_->first, tinyIt_->second};
}
dirty_ = false;
}
bool useUnorderedMap_{false};
typename TinyMap<KeyT, ValueT>::Iterator tinyIt_{nullptr};
typename std::unordered_map<KeyT, ValueT>::iterator umIt_{};
mutable Pair cached_{};
mutable bool dirty_{true};
};
DiffMap() : useUnorderedMap_(ReactNativeFeatureFlags::useUnorderedMapInDifferentiator())
{
if (useUnorderedMap_) {
unorderedMap_.emplace();
}
}
explicit DiffMap(size_t sizeHint) : useUnorderedMap_(ReactNativeFeatureFlags::useUnorderedMapInDifferentiator())
{
if (useUnorderedMap_) {
unorderedMap_.emplace();
unorderedMap_->reserve(sizeHint);
}
}
Iterator begin()
{
Iterator it;
it.useUnorderedMap_ = useUnorderedMap_;
if (useUnorderedMap_) {
it.umIt_ = unorderedMap_->begin();
} else {
it.tinyIt_ = tinyMap_.begin();
}
return it;
}
Iterator end()
{
Iterator it;
it.useUnorderedMap_ = useUnorderedMap_;
if (useUnorderedMap_) {
it.umIt_ = unorderedMap_->end();
} else {
it.tinyIt_ = tinyMap_.end();
}
return it;
}
Iterator find(KeyT key)
{
Iterator it;
it.useUnorderedMap_ = useUnorderedMap_;
if (useUnorderedMap_) {
it.umIt_ = unorderedMap_->find(key);
} else {
it.tinyIt_ = tinyMap_.find(key);
}
return it;
}
void insert(Pair pair)
{
if (useUnorderedMap_) {
unorderedMap_->insert(std::move(pair));
} else {
tinyMap_.insert(std::move(pair));
}
}
void erase(Iterator it)
{
if (useUnorderedMap_) {
unorderedMap_->erase(it.umIt_);
} else {
tinyMap_.erase(it.tinyIt_);
}
}
private:
bool useUnorderedMap_;
TinyMap<KeyT, ValueT> tinyMap_;
std::optional<std::unordered_map<KeyT, ValueT>> unorderedMap_;
};
} // namespace facebook::react
@@ -1,147 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <algorithm>
#include <utility>
/*
* Extremely simple and naive implementation of a map.
* The map is simple but it's optimized for particular constraints that we have
* here.
*
* A regular map implementation (e.g. `std::unordered_map`) has some basic
* performance guarantees like constant average insertion and lookup complexity.
* This is nice, but it's *average* complexity measured on a non-trivial amount
* of data. The regular map is a very complex data structure that using hashing,
* buckets, multiple comprising operations, multiple allocations and so on.
*
* In our particular case, we need a map for `int` to `void *` with a dozen
* values. In these conditions, nothing can beat a naive implementation using a
* stack-allocated vector. And this implementation is exactly this: no
* allocation, no hashing, no complex branching, no buckets, no iterators, no
* rehashing, no other guarantees. It's crazy limited, unsafe, and performant on
* a trivial amount of data.
*
* Besides that, we also need to optimize for insertion performance (the case
* where a bunch of views appears on the screen first time); in this
* implementation, this is as performant as vector `push_back`.
*/
template <typename KeyT, typename ValueT>
class TinyMap final {
public:
using Pair = std::pair<KeyT, ValueT>;
using Iterator = Pair *;
/**
* This must strictly only be called from outside of this class.
*/
inline Iterator begin()
{
// Force a clean so that iterating over this TinyMap doesn't iterate over
// erased elements. If all elements erased are at the front of the vector,
// then we don't need to clean.
cleanVector(erasedAtFront_ != numErased_);
Iterator it = begin_();
if (it != nullptr) {
return it + erasedAtFront_;
}
return nullptr;
}
inline Iterator end()
{
// `back()` asserts on the vector being non-empty
if (vector_.empty() || numErased_ == vector_.size()) {
return nullptr;
}
return &vector_.back() + 1;
}
inline Iterator find(KeyT key)
{
cleanVector();
react_native_assert(key != 0);
if (begin_() == nullptr) {
return end();
}
for (auto it = begin_() + erasedAtFront_; it != end(); it++) {
if (it->first == key) {
return it;
}
}
return end();
}
inline void insert(Pair pair)
{
react_native_assert(pair.first != 0);
vector_.push_back(pair);
}
inline void erase(Iterator iterator)
{
// Invalidate tag.
iterator->first = 0;
if (iterator == begin_() + erasedAtFront_) {
erasedAtFront_++;
}
numErased_++;
}
private:
/**
* Same as begin() but doesn't call cleanVector at the beginning.
*/
inline Iterator begin_()
{
// `front()` asserts on the vector being non-empty
if (vector_.empty() || vector_.size() == numErased_) {
return nullptr;
}
return &vector_.front();
}
/**
* Remove erased elements from internal vector.
* We only modify the vector if erased elements are at least half of the
* vector.
*/
inline void cleanVector(bool forceClean = false)
{
if ((numErased_ < (vector_.size() / 2) && !forceClean) || vector_.empty() || numErased_ == 0 ||
numErased_ == erasedAtFront_) {
return;
}
if (numErased_ == vector_.size()) {
vector_.clear();
} else {
vector_.erase(
std::remove_if(vector_.begin(), vector_.end(), [](const auto &item) { return item.first == 0; }),
vector_.end());
}
numErased_ = 0;
erasedAtFront_ = 0;
}
std::vector<Pair> vector_;
size_t numErased_{0};
size_t erasedAtFront_{0};
};
@@ -955,17 +955,6 @@ const definitions: FeatureFlagDefinitions = {
},
ossReleaseStage: 'canary',
},
useUnorderedMapInDifferentiator: {
defaultValue: false,
metadata: {
dateAdded: '2026-02-26',
description:
'Use std::unordered_map instead of TinyMap in the Differentiator for improved lookup performance.',
expectedReleaseValue: true,
purpose: 'experimentation',
},
ossReleaseStage: 'none',
},
viewCullingOutsetRatio: {
defaultValue: 0,
metadata: {
@@ -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<<f842431ac69c18283b0f509fc0407f85>>
* @generated SignedSource<<1d2fba4cafe542180a63997159b5cd2a>>
* @flow strict
* @noformat
*/
@@ -131,7 +131,6 @@ export type ReactNativeFeatureFlags = $ReadOnly<{
useSharedAnimatedBackend: Getter<boolean>,
useTraitHiddenOnAndroid: Getter<boolean>,
useTurboModuleInterop: Getter<boolean>,
useUnorderedMapInDifferentiator: Getter<boolean>,
viewCullingOutsetRatio: Getter<number>,
viewTransitionEnabled: Getter<boolean>,
viewTransitionUseHardwareBitmapAndroid: Getter<boolean>,
@@ -537,10 +536,6 @@ export const useTraitHiddenOnAndroid: Getter<boolean> = createNativeFlagGetter('
* In Bridgeless mode, should legacy NativeModules use the TurboModule system?
*/
export const useTurboModuleInterop: Getter<boolean> = createNativeFlagGetter('useTurboModuleInterop', false);
/**
* Use std::unordered_map instead of TinyMap in the Differentiator for improved lookup performance.
*/
export const useUnorderedMapInDifferentiator: Getter<boolean> = createNativeFlagGetter('useUnorderedMapInDifferentiator', false);
/**
* Outset the culling context frame with the provided ratio. The culling context frame size will be outset by width * ratio on the left and right, and height * ratio on the top and bottom.
*/
@@ -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<<922d3f0709d01e77b6ef4061c541130f>>
* @generated SignedSource<<c511e258f6ede1746fd8547cb774db5e>>
* @flow strict
* @noformat
*/
@@ -110,7 +110,6 @@ export interface Spec extends TurboModule {
+useSharedAnimatedBackend?: () => boolean;
+useTraitHiddenOnAndroid?: () => boolean;
+useTurboModuleInterop?: () => boolean;
+useUnorderedMapInDifferentiator?: () => boolean;
+viewCullingOutsetRatio?: () => number;
+viewTransitionEnabled?: () => boolean;
+viewTransitionUseHardwareBitmapAndroid?: () => boolean;
@@ -8283,26 +8283,6 @@ class facebook::react::SimpleThreadSafeCache {
public std::pair<const KeyT*, const ValueT*> getWithKey(const KeyT& key, facebook::react::CacheGeneratorFunction<ValueT> auto generator) const;
}
template <typename KeyT, typename ValueT>
class facebook::react::DiffMap {
public DiffMap();
public DiffMap(size_t sizeHint);
public facebook::react::DiffMap::Iterator begin();
public facebook::react::DiffMap::Iterator end();
public facebook::react::DiffMap::Iterator find(KeyT key);
public using Pair = std::pair<KeyT, ValueT>;
public void erase(facebook::react::DiffMap::Iterator it);
public void insert(facebook::react::DiffMap::Pair pair);
}
class facebook::react::DiffMap::Iterator {
public bool operator!=(const facebook::react::DiffMap::Iterator& other) const;
public bool operator==(const facebook::react::DiffMap::Iterator& other) const;
public const facebook::react::DiffMap::Pair& operator*() const;
public const facebook::react::DiffMap::Pair* operator->() const;
public facebook::react::DiffMap::Iterator& operator++();
}
template <typename Lambda>
class facebook::react::OnScopeExit {
public OnScopeExit(const Lambda&& lambda) noexcept;
@@ -8059,26 +8059,6 @@ class facebook::react::SimpleThreadSafeCache {
public std::pair<const KeyT*, const ValueT*> getWithKey(const KeyT& key, facebook::react::CacheGeneratorFunction<ValueT> auto generator) const;
}
template <typename KeyT, typename ValueT>
class facebook::react::DiffMap {
public DiffMap();
public DiffMap(size_t sizeHint);
public facebook::react::DiffMap::Iterator begin();
public facebook::react::DiffMap::Iterator end();
public facebook::react::DiffMap::Iterator find(KeyT key);
public using Pair = std::pair<KeyT, ValueT>;
public void erase(facebook::react::DiffMap::Iterator it);
public void insert(facebook::react::DiffMap::Pair pair);
}
class facebook::react::DiffMap::Iterator {
public bool operator!=(const facebook::react::DiffMap::Iterator& other) const;
public bool operator==(const facebook::react::DiffMap::Iterator& other) const;
public const facebook::react::DiffMap::Pair& operator*() const;
public const facebook::react::DiffMap::Pair* operator->() const;
public facebook::react::DiffMap::Iterator& operator++();
}
template <typename Lambda>
class facebook::react::OnScopeExit {
public OnScopeExit(const Lambda&& lambda) noexcept;
@@ -8274,26 +8274,6 @@ class facebook::react::SimpleThreadSafeCache {
public std::pair<const KeyT*, const ValueT*> getWithKey(const KeyT& key, facebook::react::CacheGeneratorFunction<ValueT> auto generator) const;
}
template <typename KeyT, typename ValueT>
class facebook::react::DiffMap {
public DiffMap();
public DiffMap(size_t sizeHint);
public facebook::react::DiffMap::Iterator begin();
public facebook::react::DiffMap::Iterator end();
public facebook::react::DiffMap::Iterator find(KeyT key);
public using Pair = std::pair<KeyT, ValueT>;
public void erase(facebook::react::DiffMap::Iterator it);
public void insert(facebook::react::DiffMap::Pair pair);
}
class facebook::react::DiffMap::Iterator {
public bool operator!=(const facebook::react::DiffMap::Iterator& other) const;
public bool operator==(const facebook::react::DiffMap::Iterator& other) const;
public const facebook::react::DiffMap::Pair& operator*() const;
public const facebook::react::DiffMap::Pair* operator->() const;
public facebook::react::DiffMap::Iterator& operator++();
}
template <typename Lambda>
class facebook::react::OnScopeExit {
public OnScopeExit(const Lambda&& lambda) noexcept;
@@ -10667,26 +10667,6 @@ class facebook::react::SimpleThreadSafeCache {
public std::pair<const KeyT*, const ValueT*> getWithKey(const KeyT& key, facebook::react::CacheGeneratorFunction<ValueT> auto generator) const;
}
template <typename KeyT, typename ValueT>
class facebook::react::DiffMap {
public DiffMap();
public DiffMap(size_t sizeHint);
public facebook::react::DiffMap::Iterator begin();
public facebook::react::DiffMap::Iterator end();
public facebook::react::DiffMap::Iterator find(KeyT key);
public using Pair = std::pair<KeyT, ValueT>;
public void erase(facebook::react::DiffMap::Iterator it);
public void insert(facebook::react::DiffMap::Pair pair);
}
class facebook::react::DiffMap::Iterator {
public bool operator!=(const facebook::react::DiffMap::Iterator& other) const;
public bool operator==(const facebook::react::DiffMap::Iterator& other) const;
public const facebook::react::DiffMap::Pair& operator*() const;
public const facebook::react::DiffMap::Pair* operator->() const;
public facebook::react::DiffMap::Iterator& operator++();
}
template <typename Lambda>
class facebook::react::OnScopeExit {
public OnScopeExit(const Lambda&& lambda) noexcept;
@@ -10116,26 +10116,6 @@ class facebook::react::SimpleThreadSafeCache {
public std::pair<const KeyT*, const ValueT*> getWithKey(const KeyT& key, facebook::react::CacheGeneratorFunction<ValueT> auto generator) const;
}
template <typename KeyT, typename ValueT>
class facebook::react::DiffMap {
public DiffMap();
public DiffMap(size_t sizeHint);
public facebook::react::DiffMap::Iterator begin();
public facebook::react::DiffMap::Iterator end();
public facebook::react::DiffMap::Iterator find(KeyT key);
public using Pair = std::pair<KeyT, ValueT>;
public void erase(facebook::react::DiffMap::Iterator it);
public void insert(facebook::react::DiffMap::Pair pair);
}
class facebook::react::DiffMap::Iterator {
public bool operator!=(const facebook::react::DiffMap::Iterator& other) const;
public bool operator==(const facebook::react::DiffMap::Iterator& other) const;
public const facebook::react::DiffMap::Pair& operator*() const;
public const facebook::react::DiffMap::Pair* operator->() const;
public facebook::react::DiffMap::Iterator& operator++();
}
template <typename Lambda>
class facebook::react::OnScopeExit {
public OnScopeExit(const Lambda&& lambda) noexcept;
@@ -10658,26 +10658,6 @@ class facebook::react::SimpleThreadSafeCache {
public std::pair<const KeyT*, const ValueT*> getWithKey(const KeyT& key, facebook::react::CacheGeneratorFunction<ValueT> auto generator) const;
}
template <typename KeyT, typename ValueT>
class facebook::react::DiffMap {
public DiffMap();
public DiffMap(size_t sizeHint);
public facebook::react::DiffMap::Iterator begin();
public facebook::react::DiffMap::Iterator end();
public facebook::react::DiffMap::Iterator find(KeyT key);
public using Pair = std::pair<KeyT, ValueT>;
public void erase(facebook::react::DiffMap::Iterator it);
public void insert(facebook::react::DiffMap::Pair pair);
}
class facebook::react::DiffMap::Iterator {
public bool operator!=(const facebook::react::DiffMap::Iterator& other) const;
public bool operator==(const facebook::react::DiffMap::Iterator& other) const;
public const facebook::react::DiffMap::Pair& operator*() const;
public const facebook::react::DiffMap::Pair* operator->() const;
public facebook::react::DiffMap::Iterator& operator++();
}
template <typename Lambda>
class facebook::react::OnScopeExit {
public OnScopeExit(const Lambda&& lambda) noexcept;
@@ -6367,26 +6367,6 @@ class facebook::react::SimpleThreadSafeCache {
public std::pair<const KeyT*, const ValueT*> getWithKey(const KeyT& key, facebook::react::CacheGeneratorFunction<ValueT> auto generator) const;
}
template <typename KeyT, typename ValueT>
class facebook::react::DiffMap {
public DiffMap();
public DiffMap(size_t sizeHint);
public facebook::react::DiffMap::Iterator begin();
public facebook::react::DiffMap::Iterator end();
public facebook::react::DiffMap::Iterator find(KeyT key);
public using Pair = std::pair<KeyT, ValueT>;
public void erase(facebook::react::DiffMap::Iterator it);
public void insert(facebook::react::DiffMap::Pair pair);
}
class facebook::react::DiffMap::Iterator {
public bool operator!=(const facebook::react::DiffMap::Iterator& other) const;
public bool operator==(const facebook::react::DiffMap::Iterator& other) const;
public const facebook::react::DiffMap::Pair& operator*() const;
public const facebook::react::DiffMap::Pair* operator->() const;
public facebook::react::DiffMap::Iterator& operator++();
}
template <typename Lambda>
class facebook::react::OnScopeExit {
public OnScopeExit(const Lambda&& lambda) noexcept;
@@ -6207,26 +6207,6 @@ class facebook::react::SimpleThreadSafeCache {
public std::pair<const KeyT*, const ValueT*> getWithKey(const KeyT& key, facebook::react::CacheGeneratorFunction<ValueT> auto generator) const;
}
template <typename KeyT, typename ValueT>
class facebook::react::DiffMap {
public DiffMap();
public DiffMap(size_t sizeHint);
public facebook::react::DiffMap::Iterator begin();
public facebook::react::DiffMap::Iterator end();
public facebook::react::DiffMap::Iterator find(KeyT key);
public using Pair = std::pair<KeyT, ValueT>;
public void erase(facebook::react::DiffMap::Iterator it);
public void insert(facebook::react::DiffMap::Pair pair);
}
class facebook::react::DiffMap::Iterator {
public bool operator!=(const facebook::react::DiffMap::Iterator& other) const;
public bool operator==(const facebook::react::DiffMap::Iterator& other) const;
public const facebook::react::DiffMap::Pair& operator*() const;
public const facebook::react::DiffMap::Pair* operator->() const;
public facebook::react::DiffMap::Iterator& operator++();
}
template <typename Lambda>
class facebook::react::OnScopeExit {
public OnScopeExit(const Lambda&& lambda) noexcept;
@@ -6358,26 +6358,6 @@ class facebook::react::SimpleThreadSafeCache {
public std::pair<const KeyT*, const ValueT*> getWithKey(const KeyT& key, facebook::react::CacheGeneratorFunction<ValueT> auto generator) const;
}
template <typename KeyT, typename ValueT>
class facebook::react::DiffMap {
public DiffMap();
public DiffMap(size_t sizeHint);
public facebook::react::DiffMap::Iterator begin();
public facebook::react::DiffMap::Iterator end();
public facebook::react::DiffMap::Iterator find(KeyT key);
public using Pair = std::pair<KeyT, ValueT>;
public void erase(facebook::react::DiffMap::Iterator it);
public void insert(facebook::react::DiffMap::Pair pair);
}
class facebook::react::DiffMap::Iterator {
public bool operator!=(const facebook::react::DiffMap::Iterator& other) const;
public bool operator==(const facebook::react::DiffMap::Iterator& other) const;
public const facebook::react::DiffMap::Pair& operator*() const;
public const facebook::react::DiffMap::Pair* operator->() const;
public facebook::react::DiffMap::Iterator& operator++();
}
template <typename Lambda>
class facebook::react::OnScopeExit {
public OnScopeExit(const Lambda&& lambda) noexcept;
-1
View File
@@ -14,7 +14,6 @@ exclude_symbols:
- "(?i)experimental"
- "unstable_"
- "UnstableLegacy"
- "TinyMap"
- "packAnimatedProps"
- "DO_NOT_USE"
- "_DEPRECATED|DEPRECATED_"