From 4e9c42832812decbd627e346a1f969502d0729d0 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Wed, 3 Jun 2020 20:45:45 -0700 Subject: [PATCH] Cache constants for MP Home NativeModules Summary: TurboModules doesn't cache invocations of getConstants(). This diff looks at which NativeModules' getConstants() methods gets repeated called in Marketplace, and caches those invocations in JS. Reviewed By: fkgozali Differential Revision: D21874124 fbshipit-source-id: 03d2318e1b6d00236ef707f9f19a640bf8c08786 --- Libraries/Utilities/NativeDeviceInfo.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Libraries/Utilities/NativeDeviceInfo.js b/Libraries/Utilities/NativeDeviceInfo.js index b29b68e0cdd..e1f2a6625de 100644 --- a/Libraries/Utilities/NativeDeviceInfo.js +++ b/Libraries/Utilities/NativeDeviceInfo.js @@ -43,7 +43,18 @@ export interface Spec extends TurboModule { } const NativeModule: Spec = TurboModuleRegistry.getEnforcing('DeviceInfo'); +let constants = null; -const NativeDeviceInfo = NativeModule; +const NativeDeviceInfo = { + getConstants(): {| + +Dimensions: DimensionsPayload, + +isIPhoneX_deprecated?: boolean, + |} { + if (constants == null) { + constants = NativeModule.getConstants(); + } + return constants; + }, +}; export default NativeDeviceInfo;