mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Experiment with HostFunction caching in TurboModules
Summary: Enables two new experiments (and the current behaviour as default) to speed up access to TurboModule methods from JS. 1) HostObject - Current behaviour 2) Prototype - Connect the TM HostObject via `__proto__`, and cache any methods accessed on the wrapper object. 3) Eager - Eagerly store all methods on the wrapper object, do not expose the HostObject to JS at all (TurboModules no longer need to be HostObjects in this scenario) Changelog: [Internal] Reviewed By: JoshuaGross, rubennorte, mdvacca Differential Revision: D36590018 fbshipit-source-id: c9565eb239eb6aeee0f06b581ff8cd72a92073fc
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d5045252f8
commit
5ae53cc051
@@ -116,4 +116,15 @@ public class ReactFeatureFlags {
|
||||
|
||||
/** Feature Flag to control RN Android scrollEventThrottle prop. */
|
||||
public static boolean enableScrollEventThrottle = false;
|
||||
|
||||
/**
|
||||
* Feature flag that controls how turbo modules are exposed to JS
|
||||
*
|
||||
* <ul>
|
||||
* <li>0 = as a HostObject
|
||||
* <li>1 = as a plain object, backed with a HostObject as prototype
|
||||
* <li>2 = as a plain object, with all methods eagerly configured
|
||||
* </ul>
|
||||
*/
|
||||
public static int turboModuleBindingMode = 0;
|
||||
}
|
||||
|
||||
+17
-1
@@ -20,6 +20,17 @@
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
constexpr static auto ReactFeatureFlagsJavaDescriptor =
|
||||
"com/facebook/react/config/ReactFeatureFlags";
|
||||
|
||||
static int getFeatureFlagValue(const char *name) {
|
||||
static const auto reactFeatureFlagsJavaDescriptor =
|
||||
jni::findClassStatic(ReactFeatureFlagsJavaDescriptor);
|
||||
const auto field =
|
||||
reactFeatureFlagsJavaDescriptor->getStaticField<jint>(name);
|
||||
return reactFeatureFlagsJavaDescriptor->getStaticFieldValue(field);
|
||||
}
|
||||
|
||||
TurboModuleManager::TurboModuleManager(
|
||||
jni::alias_ref<TurboModuleManager::javaobject> jThis,
|
||||
RuntimeExecutor runtimeExecutor,
|
||||
@@ -169,8 +180,13 @@ void TurboModuleManager::installJSIBindings() {
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
TurboModuleBindingMode bindingMode = static_cast<TurboModuleBindingMode>(
|
||||
getFeatureFlagValue("turboModuleBindingMode"));
|
||||
TurboModuleBinding::install(
|
||||
runtime, std::move(turboModuleProvider), longLivedObjectCollection_);
|
||||
runtime,
|
||||
std::move(turboModuleProvider),
|
||||
bindingMode,
|
||||
longLivedObjectCollection_);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user