Skip to content

Commit

Permalink
Move default Hermes GC config from ReactAndroid to ReactCommon
Browse files Browse the repository at this point in the history
We want to use the same GC config on iOS. We could copy it in, but I figured it would be better to move it to a shared place that can be accessed on both iOS and Android.
  • Loading branch information
Ashoat committed Jul 25, 2021
1 parent a90f8d8 commit d009c5a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include <../instrumentation/HermesMemoryDumper.h>
#include <DefaultHermesGCConfigBuilder-inl.h>
#include <HermesExecutorFactory.h>
#include <android/log.h>
#include <fbjni/fbjni.h>
Expand All @@ -31,22 +32,8 @@ 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())
return ::hermes::vm::RuntimeConfig::Builder()
.withGCConfig(defaultHermesGCConfigBuilder(heapSizeMB).build())
.build();
}

Expand Down
36 changes: 36 additions & 0 deletions ReactCommon/hermes/executor/DefaultHermesGCConfigBuilder-inl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 <cstdint>
#include <hermes/Public/GCConfig.h>
#include <hermes/Public/RuntimeConfig.h>

namespace facebook {
namespace react {

::hermes::vm::GCConfig::Builder defaultHermesGCConfigBuilder(
int64_t 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 gcConfigBuilder;
}

} // namespace react
} // namespace facebook

0 comments on commit d009c5a

Please sign in to comment.