From 97b551e68aca231cb357e4e75250d8dcc026a402 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Thu, 4 Dec 2025 13:59:07 +0000 Subject: [PATCH 1/5] perf: increase initial hermes heap size --- ...0.81.4+026+perf-increase-initial-heap-size.patch | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 patches/react-native/react-native+0.81.4+026+perf-increase-initial-heap-size.patch diff --git a/patches/react-native/react-native+0.81.4+026+perf-increase-initial-heap-size.patch b/patches/react-native/react-native+0.81.4+026+perf-increase-initial-heap-size.patch new file mode 100644 index 0000000000000..f2740e91d968a --- /dev/null +++ b/patches/react-native/react-native+0.81.4+026+perf-increase-initial-heap-size.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp b/node_modules/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp +index d09f3a7..9018067 100644 +--- a/node_modules/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp ++++ b/node_modules/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp +@@ -126,6 +126,8 @@ std::unique_ptr HermesInstance::createJSRuntime( + assert(msgQueueThread != nullptr); + + auto gcConfig = ::hermes::vm::GCConfig::Builder() ++ .withInitHeapSize(150ll * 1024 * 1024) ++ .withShouldReleaseUnused(::hermes::vm::kReleaseUnusedNone) + // Default to 3GB + .withMaxHeapSize(3072 << 20) + .withName("RNBridgeless"); From 57e6ba91182aa50606410e2783990b93deb776da Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Thu, 4 Dec 2025 19:23:04 +0000 Subject: [PATCH 2/5] Create react-native+0.81.4+001+perf-disable-hermes-young-gc-before-tti-reached.patch --- ...e-hermes-young-gc-before-tti-reached.patch | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 patches/react-native+0.81.4+001+perf-disable-hermes-young-gc-before-tti-reached.patch diff --git a/patches/react-native+0.81.4+001+perf-disable-hermes-young-gc-before-tti-reached.patch b/patches/react-native+0.81.4+001+perf-disable-hermes-young-gc-before-tti-reached.patch new file mode 100644 index 0000000000000..654f39418fa54 --- /dev/null +++ b/patches/react-native+0.81.4+001+perf-disable-hermes-young-gc-before-tti-reached.patch @@ -0,0 +1,23 @@ +diff --git a/node_modules/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp b/node_modules/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp +index d09f3a7..405a36f 100644 +--- a/node_modules/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp ++++ b/node_modules/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp +@@ -126,11 +126,17 @@ std::unique_ptr HermesInstance::createJSRuntime( + assert(msgQueueThread != nullptr); + + auto gcConfig = ::hermes::vm::GCConfig::Builder() ++ .withInitHeapSize(150ll * 1024 * 1024) ++ .withShouldReleaseUnused(::hermes::vm::kReleaseUnusedNone) + // Default to 3GB + .withMaxHeapSize(3072 << 20) + .withName("RNBridgeless"); + +- if (allocInOldGenBeforeTTI) { ++ // By enabling the `allocInOldGenBeforeTTI` flag, we prevent ++ // Hermes from running Young-Gen GC before TTI, ++ // which saves around 150-200ms on initial load. ++ // Once Old-Gen GC is triggered, it will enable Young-Gen GC again. ++ if (/*allocInOldGenBeforeTTI*/ true) { + // For the next two arguments: avoid GC before TTI + // by initializing the runtime to allocate directly + // in the old generation, but revert to normal From 2e9c6bef34e0cd1c6996f0746543e901491ca617 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Thu, 4 Dec 2025 19:23:33 +0000 Subject: [PATCH 3/5] move patch --- ...1.4+027+perf-disable-hermes-young-gc-before-tti-reached.patch} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename patches/{react-native+0.81.4+001+perf-disable-hermes-young-gc-before-tti-reached.patch => react-native/react-native+0.81.4+027+perf-disable-hermes-young-gc-before-tti-reached.patch} (100%) diff --git a/patches/react-native+0.81.4+001+perf-disable-hermes-young-gc-before-tti-reached.patch b/patches/react-native/react-native+0.81.4+027+perf-disable-hermes-young-gc-before-tti-reached.patch similarity index 100% rename from patches/react-native+0.81.4+001+perf-disable-hermes-young-gc-before-tti-reached.patch rename to patches/react-native/react-native+0.81.4+027+perf-disable-hermes-young-gc-before-tti-reached.patch From 618e0cd9eb5f666306a39f9ec4701f5fb32ff07a Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 5 Dec 2025 17:41:35 +0000 Subject: [PATCH 4/5] fix: patch invalid --- ...rf-disable-hermes-young-gc-before-tti-reached.patch | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/patches/react-native/react-native+0.81.4+027+perf-disable-hermes-young-gc-before-tti-reached.patch b/patches/react-native/react-native+0.81.4+027+perf-disable-hermes-young-gc-before-tti-reached.patch index 654f39418fa54..02cdb490a967f 100644 --- a/patches/react-native/react-native+0.81.4+027+perf-disable-hermes-young-gc-before-tti-reached.patch +++ b/patches/react-native/react-native+0.81.4+027+perf-disable-hermes-young-gc-before-tti-reached.patch @@ -1,14 +1,8 @@ diff --git a/node_modules/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp b/node_modules/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp -index d09f3a7..405a36f 100644 +index 9018067..405a36f 100644 --- a/node_modules/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp +++ b/node_modules/react-native/ReactCommon/react/runtime/hermes/HermesInstance.cpp -@@ -126,11 +126,17 @@ std::unique_ptr HermesInstance::createJSRuntime( - assert(msgQueueThread != nullptr); - - auto gcConfig = ::hermes::vm::GCConfig::Builder() -+ .withInitHeapSize(150ll * 1024 * 1024) -+ .withShouldReleaseUnused(::hermes::vm::kReleaseUnusedNone) - // Default to 3GB +@@ -132,7 +132,11 @@ std::unique_ptr HermesInstance::createJSRuntime( .withMaxHeapSize(3072 << 20) .withName("RNBridgeless"); From d6b6e347685afb059dd2bb496796c44f13def6ab Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sun, 14 Dec 2025 09:41:24 -0500 Subject: [PATCH 5/5] chore: add details.md for patches --- patches/react-native/details.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/patches/react-native/details.md b/patches/react-native/details.md index 5c8c655e6b48a..ee07c85082728 100644 --- a/patches/react-native/details.md +++ b/patches/react-native/details.md @@ -194,3 +194,17 @@ - Upstream PR/issue: There won't be any upstream changes. We need to get rid of InteractionManager - E/App issue: https://github.com/Expensify/App/issues/71913 - PR introducing patch: https://github.com/Expensify/App/pull/69535 + +### [react-native+0.81.4+026+perf-increase-initial-heap-size.patch](react-native+0.81.4+026+perf-increase-initial-heap-size.patch) + +- Reason: This patch increases the initial heap size of the Hermes runtime. This allows us to disable Hermes Young-Gen Garbage Collection (GC) in a separate patch, which improves initial TTI and app startup time. +- Upstream PR/issue: This is not intended to be upstreamed, since this is a low-level fix very specific to the Expensify app's requirements. +- E/App issue: [#76859](https://github.com/Expensify/App/issues/76859) +- PR introducing patch: [#76154](https://github.com/Expensify/App/pull/76154) + +### [react-native+0.81.4+027+perf-disable-hermes-young-gc-before-tti-reached.patch](react-native+0.81.4+027+perf-disable-hermes-young-gc-before-tti-reached.patch) + +- Reason: This patch disables Hermes Young-Gen Garbage Collection (GC), which improves initial TTI and app startup time, by delaying GC for early allocated memory to the first Old-Gen GC run. +- Upstream PR/issue: This is not intended to be upstreamed, since this is a low-level fix very specific to the Expensify app's requirements. +- E/App issue: [#76859](https://github.com/Expensify/App/issues/76859) +- PR introducing patch: [#76154](https://github.com/Expensify/App/pull/76154)