Skip to content

Commit 86fabd0

Browse files
committed
Add Hermes occupancy target experiment plumbing
1 parent 77512f2 commit 86fabd0

5 files changed

Lines changed: 30 additions & 12 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/hermes/HermesInstance.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@ import com.facebook.jni.annotations.DoNotStrip
1212
import com.facebook.react.runtime.JSRuntimeFactory
1313
import com.facebook.soloader.SoLoader
1414

15-
public class HermesInstance(allocInOldGenBeforeTTI: Boolean) :
16-
JSRuntimeFactory(initHybrid(allocInOldGenBeforeTTI)) {
15+
public class HermesInstance(
16+
allocInOldGenBeforeTTI: Boolean,
17+
useOccupancyTargetExperiment: Boolean,
18+
) : JSRuntimeFactory(initHybrid(allocInOldGenBeforeTTI, useOccupancyTargetExperiment)) {
1719

18-
public constructor() : this(false)
20+
public constructor(allocInOldGenBeforeTTI: Boolean) : this(allocInOldGenBeforeTTI, false)
21+
22+
public constructor() : this(false, false)
1923

2024
public companion object {
2125
@JvmStatic
2226
@DoNotStrip
23-
protected external fun initHybrid(allocInOldGenBeforeTTI: Boolean): HybridData
27+
protected external fun initHybrid(
28+
allocInOldGenBeforeTTI: Boolean,
29+
useOccupancyTargetExperiment: Boolean,
30+
): HybridData
2431

2532
init {
2633
SoLoader.loadLibrary("hermesinstancejni")

packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/JHermesInstance.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ namespace facebook::react {
1313

1414
jni::local_ref<JHermesInstance::jhybriddata> JHermesInstance::initHybrid(
1515
jni::alias_ref<jclass> /* unused */,
16-
bool allocInOldGenBeforeTTI) {
17-
return makeCxxInstance(allocInOldGenBeforeTTI);
16+
bool allocInOldGenBeforeTTI,
17+
bool useOccupancyTargetExperiment) {
18+
return makeCxxInstance(allocInOldGenBeforeTTI, useOccupancyTargetExperiment);
1819
}
1920

2021
void JHermesInstance::registerNatives() {
@@ -26,7 +27,10 @@ void JHermesInstance::registerNatives() {
2627
std::unique_ptr<JSRuntime> JHermesInstance::createJSRuntime(
2728
std::shared_ptr<MessageQueueThread> msgQueueThread) noexcept {
2829
return HermesInstance::createJSRuntime(
29-
nullptr, msgQueueThread, allocInOldGenBeforeTTI_);
30+
nullptr,
31+
msgQueueThread,
32+
allocInOldGenBeforeTTI_,
33+
useOccupancyTargetExperiment_);
3034
}
3135

3236
} // namespace facebook::react

packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/JHermesInstance.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ class JHermesInstance
2727

2828
static jni::local_ref<jhybriddata> initHybrid(
2929
jni::alias_ref<jclass> /* unused */,
30-
bool allocInOldGenBeforeTTI);
30+
bool allocInOldGenBeforeTTI,
31+
bool useOccupancyTargetExperiment);
3132

3233
static void registerNatives();
3334

34-
JHermesInstance(bool allocInOldGenBeforeTTI)
35-
: allocInOldGenBeforeTTI_(allocInOldGenBeforeTTI){};
35+
JHermesInstance(bool allocInOldGenBeforeTTI, bool useOccupancyTargetExperiment)
36+
: allocInOldGenBeforeTTI_(allocInOldGenBeforeTTI),
37+
useOccupancyTargetExperiment_(useOccupancyTargetExperiment){};
3638

3739
std::unique_ptr<JSRuntime> createJSRuntime(
3840
std::shared_ptr<MessageQueueThread> msgQueueThread) noexcept;
@@ -43,6 +45,7 @@ class JHermesInstance
4345
friend HybridBase;
4446

4547
bool allocInOldGenBeforeTTI_;
48+
bool useOccupancyTargetExperiment_;
4649
};
4750

4851
} // namespace facebook::react

packages/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,15 @@ class HermesJSRuntime : public JSRuntime {
126126
std::unique_ptr<JSRuntime> HermesInstance::createJSRuntime(
127127
std::shared_ptr<::hermes::vm::CrashManager> crashManager,
128128
std::shared_ptr<MessageQueueThread> msgQueueThread,
129-
bool allocInOldGenBeforeTTI) noexcept {
129+
bool allocInOldGenBeforeTTI,
130+
bool useOccupancyTargetExperiment) noexcept {
130131
assert(msgQueueThread != nullptr);
131132

132133
auto gcConfig = ::hermes::vm::GCConfig::Builder()
133134
// Default to 3GB
134135
.withMaxHeapSize(3072 << 20)
136+
.withOccupancyTarget(
137+
useOccupancyTargetExperiment ? 0.75 : 0.5)
135138
.withName("RNBridgeless");
136139

137140
if (allocInOldGenBeforeTTI) {

packages/react-native/ReactCommon/react/runtime/hermes/HermesInstance.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class HermesInstance {
1919
static std::unique_ptr<JSRuntime> createJSRuntime(
2020
std::shared_ptr<::hermes::vm::CrashManager> crashManager,
2121
std::shared_ptr<MessageQueueThread> msgQueueThread,
22-
bool allocInOldGenBeforeTTI) noexcept;
22+
bool allocInOldGenBeforeTTI,
23+
bool useOccupancyTargetExperiment = false) noexcept;
2324
};
2425

2526
} // namespace facebook::react

0 commit comments

Comments
 (0)