You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d1a8c36
Browse filesBrowse the repository at this point in the historyBrowse files
perf(mobile): use HTTP/2 on Android through app-wide Cronet engines (#9435)
Follows #8897 (iOS HTTP/2), now on main.
## What
Android gets the same app-wide shared sessions as iOS, backed by Cronet
(`cronet_http`) instead of `NSURLSession`:
- One Cronet engine per traffic class (API, media), so requests to a
host multiplex over one HTTP/2 connection and gzip is inflated natively,
off the Dart isolate.
- HTTP/2 on, HTTP cache off, QUIC off. QUIC would be a separate behavior
change, and `cronet_http`'s changelog lists DNS failures with QUIC on
cellular.
- Streamed uploads (media and voice notes) stay on `dart:io` on Android:
`CronetClient` reads a request body into memory before sending it, which
would break upload progress and copy large attachments in full.
- If no Cronet provider is available (no Google Play services), the
engine fails to build and the app keeps `dart:io`, as today.
- Transport error classification covers Cronet failures alongside
`NSURLSession` ones, so invite and pairing errors keep their friendly
messages.
## Measurements
Android emulator (API 36, arm64), profile builds of this branch and
main, signed in to the Feedback community. 8 cold starts per build,
alternating builds in blocks of 4. Times are for relay `/query` requests
started in the first 8 s.
| | main (`dart:io`) | this branch (Cronet) |
|---|---|---|
| First query response | 6.99 s | 1.99 s |
| Startup burst settled | 8.36 s | 2.78 s |
| Burst after the first connection | 1.44 s | 0.77 s |
| Query latency after the first connection, median / p90 | 165 / 1567 ms
| 106 / 158 ms |
**Unexplained stall:** most of main's startup gap is a ~5 s stall before
its first response on every cold start. Its cause is unconfirmed; my
guess is `dart:io` loading its CA store on the emulator, which HTTP/2
itself wouldn't fix, so the first two rows likely overstate the win on
real devices. The rows after the first connection exclude the stall and
are the fairer comparison. I also tried emulated EDGE throttling, but
the emulator's throttle did not slow its traffic, so there are no
slow-link numbers yet.
## Regressions
None found. Devices without Play services keep `dart:io`. Cleartext
`http://` requests keep the handle's own `dart:io` client, as on iOS.
## Testing
- Full mobile suite passes (`flutter test`, 4784 tests).
- Automated app run on the emulator: onboarding, Feedback nsec import,
channel and DM list load, and 16 cold starts with request timing. Media
loading wasn't separately exercised.
- No visible UI change, so no screenshots.
---------
Signed-off-by: Tom Brow <[email protected]>
Co-authored-by: Tom Brow <[email protected]>
/// Matches the `dart:io` transport apart from the protocol: no HTTP cache,
62
+
/// and Cronet keeps no cookies. QUIC stays off, so this changes only the
63
+
/// HTTP version.
64
+
///
65
+
/// Null when no Cronet provider is available: Cronet comes from Google Play
66
+
/// services, which some Android devices don't have. Those keep `dart:io`.
67
+
http.Client?_openCronetSession() {
68
+
finalCronetEngine engine;
69
+
try {
70
+
engine =CronetEngine.build(
71
+
cacheMode:CacheMode.disabled,
72
+
enableHttp2:true,
73
+
enableQuic:false,
74
+
);
75
+
} onJThrowablecatch (error) {
76
+
debugPrint('Cronet is unavailable, using dart:io: ${error.message}');
77
+
returnnull;
78
+
}
79
+
returnCronetClient.fromCronetEngine(engine);
80
+
}
81
+
45
82
/// A caller's handle on an app-wide session. Like closing a `dart:io` client,
46
83
/// [close] cancels the handle's requests still in flight and refuses later
47
84
/// ones, but leaves the session open for other handles. Closing a
48
-
/// `CupertinoClient` while any of its requests run would also throw.
85
+
/// `CupertinoClient` while any of its requests run would also throw, and
86
+
/// closing a `CronetClient` would stop the shared engine.
49
87
///
50
88
/// App Transport Security blocks cleartext `URLSession` loads from public
51
89
/// hosts, while saved community icons and remote media may still use
52
90
/// `http://`. Those keep the handle's own `dart:io` client, as before.
91
+
///
92
+
/// Unless [streamsUploads], a streamed request with a body (media and voice
93
+
/// note uploads) also keeps `dart:io`: `CronetClient` reads the whole body
94
+
/// into memory before sending it, so progress would reach 100% before any
95
+
/// byte left and a large attachment would be copied in full.
0 commit comments