Skip to content

Commit 0e0d2e8

Browse files
RSNarafacebook-github-bot
authored andcommitted
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 (dabca52) > 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 (82187bf), 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
1 parent 5275895 commit 0e0d2e8

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

Libraries/Network/RCTNetworking.ios.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ import type {RequestBody} from './convertRequestBody';
1818

1919
class RCTNetworking extends NativeEventEmitter {
2020
constructor() {
21-
const disableCallsIntoModule =
22-
typeof global.__disableRCTNetworkingExtraneousModuleCalls === 'function'
23-
? global.__disableRCTNetworkingExtraneousModuleCalls()
24-
: false;
25-
2621
super(NativeNetworkingIOS, {
27-
__SECRET_DISABLE_CALLS_INTO_MODULE_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: disableCallsIntoModule,
22+
__SECRET_DISABLE_CALLS_INTO_MODULE_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: true,
2823
});
2924
}
3025

0 commit comments

Comments
 (0)