Repository navigation
Encode fetch responses for DevTools only when a debugger is attached - #59717
Open
hryhoriiK97 wants to merge 1 commit into
Open
hryhoriiK97 wants to merge 1 commit into
hryhoriiK97 wants to merge 1 commit into
Conversation
NetworkEventUtil.onDataReceived Base64-encodes every response handled by a ResponseHandler, which is the blob path fetch uses by default, and passes it to InspectorNetworkReporter.maybeStoreResponseBody. The reporter drops the string unless debugging is enabled, so release builds do this work for every response and throw the result away. Check isDebuggingEnabled() before encoding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
On Android, a response handled by a
ResponseHandlergoes throughNetworkEventUtil.onDataReceived(reactContext, requestId, devToolsRequestId, data: WritableMap, rawData). That's the blob path, whichfetchuses by default. This method Base64-encodes the whole response body and passes it toInspectorNetworkReporter.maybeStoreResponseBody:The reporter only uses the string when
isDebuggingEnabled()is true, so without a debugger attached the encoded copy is thrown away. In a release build that's every response. The encoding now runs only when debugging is enabled.NetworkingModulealready avoids the same kind of work for request bodies, by building their DevTools preview only in debug builds.With a debugger attached, the same call runs as before.
Changelog:
[ANDROID] [CHANGED] -
fetchresponses are no longer Base64-encoded for DevTools when no debugger is attachedTest Plan:
Unit tests:
NetworkEventUtilTesthas two new tests, one checking thatBase64isn't touched when debugging is off, and one checking that the encoded body is stored when it's on. The first one fails without this change.87 tests, 0 failures.
yarn format-check-kotlinpasses.DevTools check with this change: debug RNTester on an Android emulator, connected to the app's Metro DevTools target over CDP. After
Network.enableand afetchevaluated in the app,Network.getResponseBodyreturned{"body":"cGFja2FnZXItc3RhdHVzOnJ1bm5pbmc=","base64Encoded":true}, which decodes to the same text JS received.Measurements on a Galaxy A16 (Android 16), release RNTester with default feature flags, compiled with
cmd package compile -m speed. A Playground screen loopsawait (await fetch(url)).json()against a local server overadb reverse. A temporary switch in the same build selects the arm. The build was a local benchmark tree with other temporary probes switched off, not this exact branch, and the switch used the sameisDebuggingEnabled()check. Each run is a fresh process with a 15 s window (20 s for 1 MB). The order is A/B/B/A twice, so 4 processes per arm, and the table shows medians:isDebuggingEnabled()check and the call, withSystem.nanoTime. CPU comes from/proc/<pid>/stat, and GC fromDebug.getRuntimeStat.I found this while profiling
fetchon the same phone: on a 100 KB response loop,onDataReceivedwas 34% of the network thread, about half of that in creating the encodedStringand about 40% inBase64.encode.🤖 Generated with Claude Code