Repository navigation
Conversation
ForwardingCookieHandler calls CookieManager.getInstance() on every request, which starts the WebView provider (Chromium) in the process: about 100 ms of CPU on background threads, several threads and tens of MB of memory, in every app whose startup does a fetch or loads a remote image. The WebView keeps its cookie store in app_webview* under the app's data directory, created the first time the provider runs in this app. When the handler is given a Context and that directory does not exist, there are no cookies to send, so get() returns none without starting the provider. The provider is started as before as soon as a response sets a cookie, or once a WebView has been used in the app (the directory then exists). NetworkingModule and FrescoModule pass the application context. Handlers created without a context behave as before. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Visual regressionNo visual differences at ios: no capture |
tomekzaw
marked this pull request as ready for review
November 17, 2026 09:17
javache
reviewed
Nov 17, 2026
| private const val COOKIE_HEADER = "Cookie" | ||
|
|
||
| /** `Context.getDir("webview", …)` as used by the WebView provider, optionally with a suffix. */ | ||
| private const val WEBVIEW_DATA_DIR_PREFIX = "app_webview" |
Contributor
There was a problem hiding this comment.
How stable / future-proof is this?
javache
reviewed
Nov 17, 2026
Contributor
There was a problem hiding this comment.
Thanks! We had previously also identified the impact to memory and startup of this component.
I wonder what the actual usage of cookie sharing is between webview and networking, and whether we'd be better off deprecating this functionality or making it opt-in, and have users explicitly share cookies to webviews.
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
ForwardingCookieHandlercallsandroid.webkit.CookieManager.getInstance()for every request made throughNetworkingModule(fetch, XHR) and through Fresco's OkHttp client (remote images). The first call starts the WebView provider (Chromium) in the app's process:WebViewFactory: Loading com.google.android.webview, its dex and ICU data,CookieMonster*/CrAsyncTaskthreads, roughly 100 ms of CPU on background threads and tens of MB of memory. Every app whose startup does afetchor shows a remote image pays this, whether or not it uses cookies or a WebView.The WebView keeps its cookie store under
app_webview*in the app's data directory, created the first time the provider runs in the app. When the handler is given aContextand that directory does not exist, there is nothing to read, soget()returns no cookies without starting the provider. The provider is started exactly as before as soon as a response sets a cookie (put()), or once the app has created a WebView (the directory then exists).NetworkingModuleandFrescoModulepass the application context; handlers created without a context behave as before.Changelog
[ANDROID] [CHANGED] - Network requests no longer start the WebView provider to read cookies while the WebView has never stored anything in the app
Benchmarks
RNTester release, arm64, real phones, dex state
verify(OPPO: OEMspeed-profile), app data cleared after each install so each arm starts from a fresh install, cold starts in interleaved blocks of 6 launches per arm. TTFD =reportFullyDrawn()on the first frame with React content, TTID =am start -W. Medians, bootstrap 95 % CIs of the median difference. RNTester triggers the path through a module-scopeImage.prefetchof a facebook.com image whose response sets no cookie.The gain is contention: the Chromium start runs on background threads while the main, JS and ReactHost threads are busy, so it shows on phones with fewer or slower cores and not on the A57. On the A16 the change removes
WebViewFactoryandlibwebviewchromium.soloading from logcat and theCookieMonsterBa/CookieMonsterClthreads from the process; baseline shows both. Startup CPU drops by about 100 ms per cold start on the A16 (simpleperf, earlier measurement of the same path), independent of what reaches TTFD.Trade-offs
app_webviewdirectory, created by the old code path on its first request, and keeps the old behaviour. Over time, new installs cover the population.Context.getDir("webview")→app_webview, with an optional suffix fromWebView.setDataDirectorySuffix). It has been that since the WebView became updatable; if a provider ever used a different directory, the only effect would be the old behaviour (provider started) once a cookie is set, or missing cookies until the firstSet-Cookieif a provider stored cookies elsewhere. The context-less constructor keeps the old behaviour as an escape hatch.File.list()of the data directory per request until the directory exists (microseconds, on OkHttp's thread); after that a cached flag.Test plan
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests "com.facebook.react.modules.network.ForwardingCookieHandlerTest"(new, Robolectric): no directory → empty, directory present → cookies returned,putthengetworks across handler instances, no-context constructor unchanged.ReactCookieJarContainerTeststill passes.ReactAndroid.apiupdated for the new constructor (validation is disabled in this repo, snapshot edited by hand).harness/launch.py,ab_states.shfrom the measurement workspace).🤖 Generated with Claude Code