Skip to content

Commit

Permalink
Roll out RCTNetworking extraneous NativeModule call removal
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Dec 18, 2020
1 parent 5275895 commit 0e0d2e8
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions Libraries/Network/RCTNetworking.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down

0 comments on commit 0e0d2e8

Please sign in to comment.