Skip to content

Commit a40f973

Browse files
Ashoatfacebook-github-bot
authored andcommitted
Remove custom Hermes config for Android (#31900)
Summary: Right now, `react-native` on Android passes in an explicit Hermes config when initializes Hermes. The upcoming version of Hermes shipping with React Native 0.66 will handle this default config itself, so there's no need to override it from Android anymore. Changelog: [Android][Changed] - Hermes initialization will no longer need an explicit configuration. Pull Request resolved: #31900 Test Plan: I compiled and ran a React Native app using the Android build, making sure to build `ReactAndroid` from source. I confirmed that the config was actually being applied by testing how much memory an application could eat before being killed. Reviewed By: sshic Differential Revision: D30675510 Pulled By: yungsters fbshipit-source-id: 5eef056893b72ddd433ee808eb08d0eb56f22f72
1 parent c13eb78 commit a40f973

File tree

5 files changed

+5
-91
lines changed

5 files changed

+5
-91
lines changed

ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/BUCK

-16
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@ rn_android_library(
1717
react_native_target("java/com/facebook/hermes/instrumentation:hermes_samplingprofiler"),
1818
react_native_target("java/com/facebook/react/bridge:bridge"),
1919
":jni",
20-
":runtimeconfig",
21-
],
22-
)
23-
24-
rn_android_library(
25-
name = "runtimeconfig",
26-
srcs = [
27-
"RuntimeConfig.java",
28-
],
29-
autoglob = False,
30-
visibility = [
31-
"PUBLIC",
32-
],
33-
deps = [
34-
react_native_dep("third-party/java/jsr-305:jsr-305"),
35-
react_native_target("java/com/facebook/hermes/instrumentation:instrumentation"),
3620
],
3721
)
3822

ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.facebook.jni.HybridData;
1111
import com.facebook.react.bridge.JavaScriptExecutor;
1212
import com.facebook.soloader.SoLoader;
13-
import javax.annotation.Nullable;
1413

1514
public class HermesExecutor extends JavaScriptExecutor {
1615
private static String mode_;
@@ -27,8 +26,8 @@ public class HermesExecutor extends JavaScriptExecutor {
2726
}
2827
}
2928

30-
HermesExecutor(@Nullable RuntimeConfig config) {
31-
super(config == null ? initHybridDefaultConfig() : initHybrid(config.heapSizeMB));
29+
HermesExecutor() {
30+
super(initHybrid());
3231
}
3332

3433
@Override
@@ -45,7 +44,5 @@ public String getName() {
4544
*/
4645
public static native boolean canLoadFile(String path);
4746

48-
private static native HybridData initHybridDefaultConfig();
49-
50-
private static native HybridData initHybrid(long heapSizeMB);
47+
private static native HybridData initHybrid();
5148
}

ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,9 @@
1414
public class HermesExecutorFactory implements JavaScriptExecutorFactory {
1515
private static final String TAG = "Hermes";
1616

17-
private final RuntimeConfig mConfig;
18-
19-
public HermesExecutorFactory() {
20-
this(new RuntimeConfig(1024));
21-
}
22-
23-
public HermesExecutorFactory(RuntimeConfig config) {
24-
mConfig = config;
25-
}
26-
2717
@Override
2818
public JavaScriptExecutor create() {
29-
return new HermesExecutor(mConfig);
19+
return new HermesExecutor();
3020
}
3121

3222
@Override

ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/OnLoad.cpp

+1-39
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <android/log.h>
1111
#include <fbjni/fbjni.h>
1212
#include <glog/logging.h>
13-
#include <hermes/Public/GCConfig.h>
14-
#include <hermes/Public/RuntimeConfig.h>
1513
#include <jni.h>
1614
#include <react/jni/JReactMarker.h>
1715
#include <react/jni/JSLogging.h>
@@ -30,26 +28,6 @@ static void hermesFatalHandler(const std::string &reason) {
3028

3129
static std::once_flag flag;
3230

33-
static ::hermes::vm::RuntimeConfig makeRuntimeConfig(jlong heapSizeMB) {
34-
namespace vm = ::hermes::vm;
35-
auto gcConfigBuilder =
36-
vm::GCConfig::Builder()
37-
.withName("RN")
38-
// For the next two arguments: avoid GC before TTI by initializing the
39-
// runtime to allocate directly in the old generation, but revert to
40-
// normal operation when we reach the (first) TTI point.
41-
.withAllocInYoung(false)
42-
.withRevertToYGAtTTI(true);
43-
44-
if (heapSizeMB > 0) {
45-
gcConfigBuilder.withMaxHeapSize(heapSizeMB << 20);
46-
}
47-
48-
return vm::RuntimeConfig::Builder()
49-
.withGCConfig(gcConfigBuilder.build())
50-
.build();
51-
}
52-
5331
static void installBindings(jsi::Runtime &runtime) {
5432
react::Logger androidLogger =
5533
static_cast<void (*)(const std::string &, unsigned int)>(
@@ -67,8 +45,7 @@ class HermesExecutorHolder
6745
static constexpr auto kJavaDescriptor =
6846
"Lcom/facebook/hermes/reactexecutor/HermesExecutor;";
6947

70-
static jni::local_ref<jhybriddata> initHybridDefaultConfig(
71-
jni::alias_ref<jclass>) {
48+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>) {
7249
JReactMarker::setLogPerfMarkerIfNeeded();
7350

7451
std::call_once(flag, []() {
@@ -78,28 +55,13 @@ class HermesExecutorHolder
7855
std::make_unique<HermesExecutorFactory>(installBindings));
7956
}
8057

81-
static jni::local_ref<jhybriddata> initHybrid(
82-
jni::alias_ref<jclass>,
83-
jlong heapSizeMB) {
84-
JReactMarker::setLogPerfMarkerIfNeeded();
85-
auto runtimeConfig = makeRuntimeConfig(heapSizeMB);
86-
std::call_once(flag, []() {
87-
facebook::hermes::HermesRuntime::setFatalHandler(hermesFatalHandler);
88-
});
89-
return makeCxxInstance(std::make_unique<HermesExecutorFactory>(
90-
installBindings, JSIExecutor::defaultTimeoutInvoker, runtimeConfig));
91-
}
92-
9358
static bool canLoadFile(jni::alias_ref<jclass>, const std::string &path) {
9459
return true;
9560
}
9661

9762
static void registerNatives() {
9863
registerHybrid(
9964
{makeNativeMethod("initHybrid", HermesExecutorHolder::initHybrid),
100-
makeNativeMethod(
101-
"initHybridDefaultConfig",
102-
HermesExecutorHolder::initHybridDefaultConfig),
10365
makeNativeMethod("canLoadFile", HermesExecutorHolder::canLoadFile)});
10466
}
10567

ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/RuntimeConfig.java

-19
This file was deleted.

0 commit comments

Comments
 (0)