Skip to content

Commit

Permalink
Remove custom Hermes config for Android (#31900)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ashoat authored and facebook-github-bot committed Sep 2, 2021
1 parent c13eb78 commit a40f973
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 91 deletions.
16 changes: 0 additions & 16 deletions ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ rn_android_library(
react_native_target("java/com/facebook/hermes/instrumentation:hermes_samplingprofiler"),
react_native_target("java/com/facebook/react/bridge:bridge"),
":jni",
":runtimeconfig",
],
)

rn_android_library(
name = "runtimeconfig",
srcs = [
"RuntimeConfig.java",
],
autoglob = False,
visibility = [
"PUBLIC",
],
deps = [
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/hermes/instrumentation:instrumentation"),
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.facebook.jni.HybridData;
import com.facebook.react.bridge.JavaScriptExecutor;
import com.facebook.soloader.SoLoader;
import javax.annotation.Nullable;

public class HermesExecutor extends JavaScriptExecutor {
private static String mode_;
Expand All @@ -27,8 +26,8 @@ public class HermesExecutor extends JavaScriptExecutor {
}
}

HermesExecutor(@Nullable RuntimeConfig config) {
super(config == null ? initHybridDefaultConfig() : initHybrid(config.heapSizeMB));
HermesExecutor() {
super(initHybrid());
}

@Override
Expand All @@ -45,7 +44,5 @@ public String getName() {
*/
public static native boolean canLoadFile(String path);

private static native HybridData initHybridDefaultConfig();

private static native HybridData initHybrid(long heapSizeMB);
private static native HybridData initHybrid();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,9 @@
public class HermesExecutorFactory implements JavaScriptExecutorFactory {
private static final String TAG = "Hermes";

private final RuntimeConfig mConfig;

public HermesExecutorFactory() {
this(new RuntimeConfig(1024));
}

public HermesExecutorFactory(RuntimeConfig config) {
mConfig = config;
}

@Override
public JavaScriptExecutor create() {
return new HermesExecutor(mConfig);
return new HermesExecutor();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <android/log.h>
#include <fbjni/fbjni.h>
#include <glog/logging.h>
#include <hermes/Public/GCConfig.h>
#include <hermes/Public/RuntimeConfig.h>
#include <jni.h>
#include <react/jni/JReactMarker.h>
#include <react/jni/JSLogging.h>
Expand All @@ -30,26 +28,6 @@ static void hermesFatalHandler(const std::string &reason) {

static std::once_flag flag;

static ::hermes::vm::RuntimeConfig makeRuntimeConfig(jlong heapSizeMB) {
namespace vm = ::hermes::vm;
auto gcConfigBuilder =
vm::GCConfig::Builder()
.withName("RN")
// For the next two arguments: avoid GC before TTI by initializing the
// runtime to allocate directly in the old generation, but revert to
// normal operation when we reach the (first) TTI point.
.withAllocInYoung(false)
.withRevertToYGAtTTI(true);

if (heapSizeMB > 0) {
gcConfigBuilder.withMaxHeapSize(heapSizeMB << 20);
}

return vm::RuntimeConfig::Builder()
.withGCConfig(gcConfigBuilder.build())
.build();
}

static void installBindings(jsi::Runtime &runtime) {
react::Logger androidLogger =
static_cast<void (*)(const std::string &, unsigned int)>(
Expand All @@ -67,8 +45,7 @@ class HermesExecutorHolder
static constexpr auto kJavaDescriptor =
"Lcom/facebook/hermes/reactexecutor/HermesExecutor;";

static jni::local_ref<jhybriddata> initHybridDefaultConfig(
jni::alias_ref<jclass>) {
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>) {
JReactMarker::setLogPerfMarkerIfNeeded();

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

static jni::local_ref<jhybriddata> initHybrid(
jni::alias_ref<jclass>,
jlong heapSizeMB) {
JReactMarker::setLogPerfMarkerIfNeeded();
auto runtimeConfig = makeRuntimeConfig(heapSizeMB);
std::call_once(flag, []() {
facebook::hermes::HermesRuntime::setFatalHandler(hermesFatalHandler);
});
return makeCxxInstance(std::make_unique<HermesExecutorFactory>(
installBindings, JSIExecutor::defaultTimeoutInvoker, runtimeConfig));
}

static bool canLoadFile(jni::alias_ref<jclass>, const std::string &path) {
return true;
}

static void registerNatives() {
registerHybrid(
{makeNativeMethod("initHybrid", HermesExecutorHolder::initHybrid),
makeNativeMethod(
"initHybridDefaultConfig",
HermesExecutorHolder::initHybridDefaultConfig),
makeNativeMethod("canLoadFile", HermesExecutorHolder::canLoadFile)});
}

Expand Down

This file was deleted.

0 comments on commit a40f973

Please sign in to comment.