mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Move RuntimeScheduler initialisation to the start of the runtime
Summary: Changelog: [internal] Reland of D29131766 (https://github.com/facebook/react-native/commit/18165367b0347fc46cd52a6ac00afcf62d05cb30) which had to reverted because it caused binary size regression in instagram. Size check for `automation_instagram_stablesize_release` and `automation_igtv_release` {F626711916} Reviewed By: JoshuaGross Differential Revision: D29263302 fbshipit-source-id: cc8f5609ebaed9ddf666f7c57cdbf3dbf77a8f78
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ad0ccac0d6
commit
130b0f69ee
@@ -48,6 +48,7 @@ rn_android_library(
|
||||
react_native_target("java/com/facebook/react/config:config"),
|
||||
react_native_target("java/com/facebook/react/turbomodule/core:core"),
|
||||
react_native_target("java/com/facebook/react/turbomodule/core/interfaces:interfaces"),
|
||||
react_native_target("java/com/facebook/react/runtimescheduler:runtimescheduler"),
|
||||
],
|
||||
exported_deps = [
|
||||
react_native_target("java/com/facebook/react/modules/core:core"),
|
||||
|
||||
@@ -91,6 +91,7 @@ import com.facebook.react.modules.core.ReactChoreographer;
|
||||
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
|
||||
import com.facebook.react.modules.fabric.ReactFabric;
|
||||
import com.facebook.react.packagerconnection.RequestHandler;
|
||||
import com.facebook.react.runtimescheduler.RuntimeSchedulerManager;
|
||||
import com.facebook.react.surface.ReactStage;
|
||||
import com.facebook.react.turbomodule.core.TurboModuleManager;
|
||||
import com.facebook.react.turbomodule.core.TurboModuleManagerDelegate;
|
||||
@@ -162,6 +163,7 @@ public class ReactInstanceManager {
|
||||
private final DevSupportManager mDevSupportManager;
|
||||
private final boolean mUseDeveloperSupport;
|
||||
private @Nullable ComponentNameResolverManager mComponentNameResolverManager;
|
||||
private @Nullable RuntimeSchedulerManager mRuntimeSchedulerManager;
|
||||
private final @Nullable NotThreadSafeBridgeIdleDebugListener mBridgeIdleDebugListener;
|
||||
private final Object mReactContextLock = new Object();
|
||||
private @Nullable volatile ReactContext mCurrentReactContext;
|
||||
@@ -718,6 +720,7 @@ public class ReactInstanceManager {
|
||||
mViewManagerNames = null;
|
||||
}
|
||||
mComponentNameResolverManager = null;
|
||||
mRuntimeSchedulerManager = null;
|
||||
FLog.d(ReactConstants.TAG, "ReactInstanceManager has been destroyed");
|
||||
}
|
||||
|
||||
@@ -1350,6 +1353,10 @@ public class ReactInstanceManager {
|
||||
});
|
||||
catalystInstance.setGlobalVariable("__fbStaticViewConfig", "true");
|
||||
}
|
||||
if (ReactFeatureFlags.enableRuntimeScheduler) {
|
||||
mRuntimeSchedulerManager = new RuntimeSchedulerManager(catalystInstance.getRuntimeExecutor());
|
||||
}
|
||||
|
||||
ReactMarker.logMarker(ReactMarkerConstants.PRE_RUN_JS_BUNDLE_START);
|
||||
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "runJSBundle");
|
||||
catalystInstance.runJSBundle();
|
||||
|
||||
@@ -44,6 +44,8 @@ public class ReactFeatureFlags {
|
||||
/** Enables Static ViewConfig in RN Android native code. */
|
||||
public static boolean enableExperimentalStaticViewConfigs = false;
|
||||
|
||||
public static boolean enableRuntimeScheduler = false;
|
||||
|
||||
/** Enables a more aggressive cleanup during destruction of ReactContext */
|
||||
public static boolean enableReactContextCleanupFix = false;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ LOCAL_MODULE := fabricjni
|
||||
|
||||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := libreactconfig librrc_slider librrc_progressbar librrc_switch librrc_modal libyoga libglog libfb libfbjni libglog_init libfolly_json libfolly_futures libreact_render_mounting libreactnativeutilsjni libreact_utils libreact_render_debug libreact_render_graphics libreact_render_core react_render_componentregistry librrc_view librrc_unimplementedview librrc_root librrc_scrollview libbetter libreact_render_attributedstring libreact_render_uimanager libreact_render_templateprocessor libreact_render_scheduler libreact_render_animations libreact_render_imagemanager libreact_render_textlayoutmanager libreact_codegen_rncore rrc_text librrc_image librrc_textinput librrc_picker libreact_debug libreact_render_mapbuffer libmapbufferjni libreact_render_telemetry libreact_render_runtimescheduler
|
||||
LOCAL_SHARED_LIBRARIES := libreactconfig librrc_slider librrc_progressbar librrc_switch librrc_modal libyoga libglog libfb libfbjni libglog_init libfolly_json libfolly_futures libreact_render_mounting libreactnativeutilsjni libreact_utils libreact_render_debug libreact_render_graphics libreact_render_core react_render_componentregistry librrc_view librrc_unimplementedview librrc_root librrc_scrollview libbetter libreact_render_attributedstring libreact_render_uimanager libreact_render_templateprocessor libreact_render_scheduler libreact_render_animations libreact_render_imagemanager libreact_render_textlayoutmanager libreact_codegen_rncore rrc_text librrc_image librrc_textinput librrc_picker libreact_debug libreact_render_mapbuffer libmapbufferjni libreact_render_telemetry
|
||||
|
||||
LOCAL_STATIC_LIBRARIES :=
|
||||
|
||||
@@ -57,7 +57,6 @@ $(call import-module,react/renderer/graphics)
|
||||
$(call import-module,react/renderer/imagemanager)
|
||||
$(call import-module,react/renderer/mapbuffer)
|
||||
$(call import-module,react/renderer/mounting)
|
||||
$(call import-module,react/renderer/runtimescheduler)
|
||||
$(call import-module,react/renderer/scheduler)
|
||||
$(call import-module,react/renderer/templateprocessor)
|
||||
$(call import-module,react/renderer/textlayoutmanager)
|
||||
|
||||
@@ -34,7 +34,6 @@ rn_xplat_cxx_library(
|
||||
react_native_xplat_target("react/renderer/scheduler:scheduler"),
|
||||
react_native_xplat_target("react/renderer/componentregistry:componentregistry"),
|
||||
react_native_xplat_target("react/renderer/components/scrollview:scrollview"),
|
||||
react_native_xplat_target("react/renderer/runtimescheduler:runtimescheduler"),
|
||||
react_native_xplat_target("runtimeexecutor:runtimeexecutor"),
|
||||
react_native_target("jni/react/jni:jni"),
|
||||
"//xplat/fbsystrace:fbsystrace",
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_android_library")
|
||||
|
||||
rn_android_library(
|
||||
name = "runtimescheduler",
|
||||
srcs = glob(["**/*.java"]),
|
||||
autoglob = False,
|
||||
is_androidx = True,
|
||||
labels = ["supermodule:xplat/default/public.react_native.infra"],
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
deps = [
|
||||
react_native_target("java/com/facebook/react/runtimescheduler/jni:jni"),
|
||||
"//fbandroid/java/com/facebook/proguard/annotations:annotations",
|
||||
react_native_dep("third-party/android/androidx:annotation"),
|
||||
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
|
||||
react_native_dep("libraries/fbjni:java"),
|
||||
react_native_target("java/com/facebook/react/bridge:bridge"),
|
||||
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
|
||||
],
|
||||
)
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.runtimescheduler;
|
||||
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.proguard.annotations.DoNotStripAny;
|
||||
import com.facebook.react.bridge.RuntimeExecutor;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
@DoNotStripAny
|
||||
public class RuntimeSchedulerManager {
|
||||
|
||||
static {
|
||||
staticInit();
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
@SuppressWarnings("unused")
|
||||
private final HybridData mHybridData;
|
||||
|
||||
public RuntimeSchedulerManager(RuntimeExecutor runtimeExecutor) {
|
||||
mHybridData = initHybrid(runtimeExecutor);
|
||||
installJSIBindings();
|
||||
}
|
||||
|
||||
private native HybridData initHybrid(RuntimeExecutor runtimeExecutor);
|
||||
|
||||
private native void installJSIBindings();
|
||||
|
||||
private static void staticInit() {
|
||||
SoLoader.loadLibrary("runtimeschedulerjni");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := runtimeschedulerjni
|
||||
|
||||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := libglog libfb libfbjni libglog_init libreact_render_runtimescheduler librrc_native
|
||||
|
||||
LOCAL_STATIC_LIBRARIES :=
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/
|
||||
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/
|
||||
|
||||
LOCAL_CFLAGS := \
|
||||
-DLOG_TAG=\"ReacTNative\"
|
||||
|
||||
LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
$(call import-module,fbgloginit)
|
||||
$(call import-module,fb)
|
||||
$(call import-module,fbjni)
|
||||
$(call import-module,glog)
|
||||
|
||||
$(call import-module,react/renderer/runtimescheduler)
|
||||
@@ -0,0 +1,35 @@
|
||||
load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_target", "react_native_xplat_target", "rn_xplat_cxx_library", "subdir_glob")
|
||||
|
||||
rn_xplat_cxx_library(
|
||||
name = "jni",
|
||||
srcs = glob(["*.cpp"]),
|
||||
headers = glob(["*.h"]),
|
||||
header_namespace = "",
|
||||
exported_headers = subdir_glob(
|
||||
[
|
||||
("", "**/*.h"),
|
||||
],
|
||||
prefix = "react/runtimescheduler",
|
||||
),
|
||||
compiler_flags = [
|
||||
"-fexceptions",
|
||||
"-frtti",
|
||||
"-std=c++17",
|
||||
"-Wall",
|
||||
],
|
||||
fbandroid_allow_jni_merging = True,
|
||||
labels = ["supermodule:xplat/default/public.react_native.infra"],
|
||||
platforms = (ANDROID),
|
||||
preprocessor_flags = [
|
||||
"-DLOG_TAG=\"ReactNative\"",
|
||||
"-DWITH_FBSYSTRACE=1",
|
||||
],
|
||||
soname = "libruntimeschedulerjni.$(ext)",
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
react_native_xplat_target("react/renderer/runtimescheduler:runtimescheduler"),
|
||||
react_native_xplat_target("runtimeexecutor:runtimeexecutor"),
|
||||
react_native_target("jni/react/jni:jni"),
|
||||
FBJNI_TARGET,
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
|
||||
#include "RuntimeSchedulerManager.h"
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
|
||||
return facebook::jni::initialize(
|
||||
vm, [] { facebook::react::RuntimeSchedulerManager::registerNatives(); });
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <react/renderer/runtimescheduler/RuntimeScheduler.h>
|
||||
#include <react/renderer/runtimescheduler/RuntimeSchedulerBinding.h>
|
||||
|
||||
#include "RuntimeSchedulerManager.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
RuntimeSchedulerManager::RuntimeSchedulerManager(
|
||||
RuntimeExecutor runtimeExecutor)
|
||||
: runtimeExecutor_(runtimeExecutor) {}
|
||||
|
||||
jni::local_ref<RuntimeSchedulerManager::jhybriddata>
|
||||
RuntimeSchedulerManager::initHybrid(
|
||||
jni::alias_ref<jclass>,
|
||||
jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutor) {
|
||||
return makeCxxInstance(runtimeExecutor->cthis()->get());
|
||||
}
|
||||
|
||||
void RuntimeSchedulerManager::registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", RuntimeSchedulerManager::initHybrid),
|
||||
makeNativeMethod(
|
||||
"installJSIBindings", RuntimeSchedulerManager::installJSIBindings),
|
||||
});
|
||||
}
|
||||
|
||||
void RuntimeSchedulerManager::installJSIBindings() {
|
||||
runtimeExecutor_([runtimeExecutor = runtimeExecutor_](jsi::Runtime &runtime) {
|
||||
auto runtimeScheduler = std::make_shared<RuntimeScheduler>(runtimeExecutor);
|
||||
RuntimeSchedulerBinding::createAndInstallIfNeeded(
|
||||
runtime, runtimeScheduler);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its 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 <ReactCommon/CallInvokerHolder.h>
|
||||
#include <ReactCommon/RuntimeExecutor.h>
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <react/jni/JRuntimeExecutor.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class RuntimeSchedulerManager
|
||||
: public facebook::jni::HybridClass<RuntimeSchedulerManager> {
|
||||
public:
|
||||
static auto constexpr kJavaDescriptor =
|
||||
"Lcom/facebook/react/runtimescheduler/RuntimeSchedulerManager;";
|
||||
|
||||
static facebook::jni::local_ref<jhybriddata> initHybrid(
|
||||
jni::alias_ref<jclass>,
|
||||
facebook::jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutor);
|
||||
|
||||
static void registerNatives();
|
||||
|
||||
private:
|
||||
friend HybridBase;
|
||||
RuntimeExecutor runtimeExecutor_;
|
||||
|
||||
void installJSIBindings();
|
||||
|
||||
explicit RuntimeSchedulerManager(RuntimeExecutor runtimeExecutor);
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
Reference in New Issue
Block a user