From 0916df99511d6918ea905c2a9df45bccc1fd332a Mon Sep 17 00:00:00 2001 From: Paige Sun Date: Wed, 20 Apr 2022 10:59:57 -0700 Subject: [PATCH] Add MC to test disabling React Native invalidation under memory pressure Summary: Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D35732504 fbshipit-source-id: d81d6ddefc98d1e73be697c3eef8a2c90104658c --- React/Base/RCTConstants.h | 12 ++++++++++++ React/Base/RCTConstants.m | 31 +++++++++++++++++++++++++++++++ React/CxxBridge/RCTCxxBridge.mm | 3 ++- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/React/Base/RCTConstants.h b/React/Base/RCTConstants.h index cc51b2e780f..30bb6eedef5 100644 --- a/React/Base/RCTConstants.h +++ b/React/Base/RCTConstants.h @@ -21,3 +21,15 @@ RCT_EXTERN void RCTExperimentSetPreemptiveViewAllocationDisabled(BOOL value); */ RCT_EXTERN BOOL RCTGetDispatchW3CPointerEvents(void); RCT_EXTERN void RCTSetDispatchW3CPointerEvents(BOOL value); + +/* + * Memory Pressure Unloading + */ +RCT_EXTERN BOOL RCTGetDisableBridgeMemoryPressureUnload(void); +RCT_EXTERN void RCTSetDisableBridgeMemoryPressureUnload(BOOL value); + +/* + * Memory Pressure Unloading Level + */ +RCT_EXTERN BOOL RCTGetMemoryPressureUnloadLevel(void); +RCT_EXTERN void RCTSetMemoryPressureUnloadLevel(int value); diff --git a/React/Base/RCTConstants.m b/React/Base/RCTConstants.m index 75b76d708f7..707818cea0c 100644 --- a/React/Base/RCTConstants.m +++ b/React/Base/RCTConstants.m @@ -39,3 +39,34 @@ void RCTSetDispatchW3CPointerEvents(BOOL value) { RCTDispatchW3CPointerEvents = value; } + +/* + * Memory Pressure Unloading + */ +static BOOL RCTDisableBridgeMemoryPressureUnload = NO; + +BOOL RCTGetDisableBridgeMemoryPressureUnload() +{ + return RCTDisableBridgeMemoryPressureUnload; +} + +void RCTSetDisableBridgeMemoryPressureUnload(BOOL value) +{ + RCTDisableBridgeMemoryPressureUnload = value; +} + +/* + * Memory Pressure Unloading Level for experimentation only. + * Default is 15, which is TRIM_MEMORY_RUNNING_CRITICAL. + */ +static int RCTMemoryPressureUnloadLevel = 15; + +BOOL RCTGetMemoryPressureUnloadLevel() +{ + return RCTMemoryPressureUnloadLevel; +} + +void RCTSetMemoryPressureUnloadLevel(int value) +{ + RCTMemoryPressureUnloadLevel = value; +} diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 2454980a9bb..cad9d74f02b 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -359,7 +359,8 @@ struct RCTInstanceCallback : public InstanceCallback { // in case if some other tread resets it. auto reactInstance = _reactInstance; if (reactInstance) { - reactInstance->handleMemoryPressure(15 /* TRIM_MEMORY_RUNNING_CRITICAL */); + int unloadLevel = RCTGetMemoryPressureUnloadLevel(); + reactInstance->handleMemoryPressure(unloadLevel); } }