Skip to content

Commit 1c04cf5

Browse files
huntiefacebook-github-bot
authored andcommitted
Minimize operations in RCTInspectorNetworkReporter in prod (facebook#50242)
Summary: Pull Request resolved: facebook#50242 Similar to D71636694, adds conditional compile to `RCTInspectorNetworkReporter.mm` to minimize code size and operations performed in production builds. Specifically: - Expensive copy of `httpBody` is eliminated. - Other optional fields that are only mapped when CDP support is enabled are also omitted. Changelog: [Internal] Reviewed By: hoxyq Differential Revision: D71637716 fbshipit-source-id: 6c7688b1ac82d2b1047b42a812834a7dfb37cd0f
1 parent 793094f commit 1c04cf5

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

packages/react-native/Libraries/Network/RCTInspectorNetworkReporter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* [Experimental] An interface for reporting network events to the modern
1414
* debugger server and Web Performance APIs.
1515
*
16+
* In a production (non dev or profiling) build, CDP reporting is disabled.
17+
*
1618
* This is a helper class wrapping
1719
* `facebook::react::jsinspector_modern::NetworkReporter`.
1820
*/

packages/react-native/Libraries/Network/RCTInspectorNetworkReporter.mm

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
#import <jsinspector-modern/network/NetworkReporter.h>
1111

12-
namespace {
13-
1412
using namespace facebook::react::jsinspector_modern;
1513

14+
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
15+
namespace {
16+
1617
Headers convertNSDictionaryToHeaders(const NSDictionary<NSString *, NSString *> *headers)
1718
{
1819
Headers responseHeaders;
@@ -23,6 +24,7 @@ Headers convertNSDictionaryToHeaders(const NSDictionary<NSString *, NSString *>
2324
}
2425

2526
} // namespace
27+
#endif
2628

2729
@implementation RCTInspectorNetworkReporter {
2830
}
@@ -34,8 +36,11 @@ + (void)reportRequestStart:(NSNumber *)requestId
3436
RequestInfo requestInfo;
3537
requestInfo.url = [request.URL absoluteString].UTF8String;
3638
requestInfo.httpMethod = [request.HTTPMethod UTF8String];
39+
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
40+
// Debug build: Process additional request info for CDP reporting
3741
requestInfo.headers = convertNSDictionaryToHeaders(request.allHTTPHeaderFields);
3842
requestInfo.httpBody = std::string((const char *)request.HTTPBody.bytes, request.HTTPBody.length);
43+
#endif
3944

4045
NetworkReporter::getInstance().reportRequestStart(
4146
requestId.stringValue.UTF8String, requestInfo, encodedDataLength, std::nullopt);
@@ -49,7 +54,11 @@ + (void)reportResponseStart:(NSNumber *)requestId
4954
ResponseInfo responseInfo;
5055
responseInfo.url = response.URL.absoluteString.UTF8String;
5156
responseInfo.statusCode = statusCode;
57+
58+
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
59+
// Debug build: Process additional request info for CDP reporting
5260
responseInfo.headers = convertNSDictionaryToHeaders(headers);
61+
#endif
5362

5463
NetworkReporter::getInstance().reportResponseStart(
5564
requestId.stringValue.UTF8String, responseInfo, response.expectedContentLength);

packages/react-native/scripts/cocoapods/utils.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def self.set_gcc_preprocessor_definition_for_React_hermes(installer)
5151

5252
def self.set_gcc_preprocessor_definition_for_debugger(installer)
5353
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "REACT_NATIVE_DEBUGGER_ENABLED=1", "React-jsinspector", :debug)
54+
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "REACT_NATIVE_DEBUGGER_ENABLED=1", "React-RCTNetwork", :debug)
5455
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "REACT_NATIVE_DEBUGGER_ENABLED_DEVONLY=1", "React-jsinspector", :debug)
56+
self.add_build_settings_to_pod(installer, "GCC_PREPROCESSOR_DEFINITIONS", "REACT_NATIVE_DEBUGGER_ENABLED_DEVONLY=1", "React-RCTNetwork", :debug)
5557
end
5658

5759
def self.turn_off_resource_bundle_react_core(installer)

0 commit comments

Comments
 (0)