From 0e0d2e84f56ea233e72d980ff6bd9797df250553 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Thu, 17 Dec 2020 17:22:11 -0800 Subject: [PATCH] Roll out RCTNetworking extraneous NativeModule call removal Summary: ## Context Every time we call RCTNetworking.sendRequest(), we [set up six event listeners inside XMLHttpRequest](https://fburl.com/diffusion/85k6ou5w) by calling RCTNetworking.addListener(). Seeing how RCTNetworking.addListener() is implemented, each call results in two async NativeModule call: [one to addListener()](https://fburl.com/diffusion/ng21jek6), and [another to removeEventListener()](https://fburl.com/diffusion/nua3y973). For RCTNetworking, both of these NativeModule calls are unnecessary, as explained in D24272663 (https://github.com/facebook/react-native/commit/dabca52f77799bcdedb6b0ec44b1f6297483a46d) > RCTNetworking.startObserving and RCTNetworking.stopObserving don't exist. The main purpose of RCTEventEmitter.addListener is to call these methods, and increment the _listeners counter, so that we can start dispatching events when _listeners > 0. In D24272560 (https://github.com/facebook/react-native/commit/82187bfb6b54fdffc5dadaa56e8bf97d2209708a), I made RCTEventEmitter dispatch events even when _listeners <= 0. This is sufficient for us to stop calling these two RCTNetworking methods entirely. Therefore, this experiment gets rid of on average 6-8 NativeModule method calls for every network call we make in React Native on iOS. Reviewed By: PeteTheHeat Differential Revision: D25618704 fbshipit-source-id: 0da20475a0882ed737cf32de27f266fd2cd016af --- Libraries/Network/RCTNetworking.ios.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Libraries/Network/RCTNetworking.ios.js b/Libraries/Network/RCTNetworking.ios.js index bc1081aab35..b10a833ad19 100644 --- a/Libraries/Network/RCTNetworking.ios.js +++ b/Libraries/Network/RCTNetworking.ios.js @@ -18,13 +18,8 @@ import type {RequestBody} from './convertRequestBody'; class RCTNetworking extends NativeEventEmitter { constructor() { - const disableCallsIntoModule = - typeof global.__disableRCTNetworkingExtraneousModuleCalls === 'function' - ? global.__disableRCTNetworkingExtraneousModuleCalls() - : false; - super(NativeNetworkingIOS, { - __SECRET_DISABLE_CALLS_INTO_MODULE_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: disableCallsIntoModule, + __SECRET_DISABLE_CALLS_INTO_MODULE_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: true, }); }