| 6 | no renderer at all (`NullRenderer` in `apps/android/demo/.../Bench.kt` answers |
| 7 | `ready` and one fixed size), so the cost of the renderer reads as a difference. |
| 8 |
| 9 | ## Method |
| 10 |
| 11 | `--es autorun bench` in the Android demo (`Bench.kt`) creates 20 hosts one |
| 12 | after another, like a chat scrolled to the last message: the next one after |
| 13 | the previous one's `loaded` plus 200 ms, the list scrolled to the new one. All |
| 14 | 20 live at the same time, attached to the window (Column, not LazyColumn: the |
| 15 | worst case without snapshot-and-drop), are held for 8 seconds, then destroyed. |
| 16 | The corpus is the same as in the iOS feed: `compat`, then the beginning of |
| 17 | `generated/with-profile`. |
| 18 |
| 19 | Per widget: the `WidgetHost` constructor time on the main thread (for the |
| 20 | first WebView in the process this is loading the Chromium provider), the |
| 21 | `rendererReadyMs` / `firstContentMs` / `loadedMs` clocks (the same definitions |
| 22 | as on iOS), late time and the worst main-thread frame during start-up |
| 23 | (Choreographer, re-posted every vsync). Per phase (before the first, after the |
| 24 | first, 20 live, after destroy): process PSS via `Debug.getMemoryInfo`. The |
| 25 | `scripts/android-bench.sh` script captures `dumpsys meminfo` during the hold: |
| 26 | the WebView renderer lives in `com.google.android.webview:sandboxed_process0` |
| 27 | under an isolated uid, one per application, and the application does not see it. |
| 28 |
| 29 | Machine: the `twidget-35` emulator (API 35, arm64 on Apple Silicon, `-gpu host`, |
| 30 | started with `-memory 4096`; the stock 2 GB went into swap), WebView 124, debug |
| 31 | build of the demo (native code -O2, Blitz and litehtml — release). Two rounds, |
| 32 | the numbers are from the second; the first matches, except for the outliers of |
| 33 | the first launch after installation (the `.so` pages not yet in the cache: first |
| 34 | Blitz 126 ms instead of 53, first litehtml 237 instead of 60) and one Blitz run |
| 35 | when the emulator was busy with a neighbouring session. |
| 36 |
| 37 | ```bash |
| 38 | cd apps/android && ./gradlew :demo:installDebug |
| 39 | scripts/android-bench.sh webview 20 # cold process |
| 40 | scripts/android-bench.sh webview 20 prewarm # a spare WebView created and loaded at start-up, as a messenger would do |
| 41 | scripts/android-bench.sh blitz 20 ; scripts/android-bench.sh litehtml 20 ; scripts/android-bench.sh none 20 |
| 42 | python3 -I scripts/android-bench-print.py --table webview-20 webview-prewarm-20 none-20 blitz-20 litehtml-20 # or the name of a single report |
| 43 | ``` |
| 44 |
| 45 | ## Start-up |
| 46 |
| 47 | Widgets 2–20, median / p90, ms from host creation: |
| 48 |
| 49 | | | constructor (main thread) | `ready` | first content | `loaded` | |
| 50 | |---|---|---|---|---| |
| 51 | | WebView | 23 / 28 | 71 / 87 | 121 / 153 | 121 / 216 | |
| 52 | | WebView, prewarmed | 27 / 35 | 76 / 94 | 133 / 158 | 116 / 242 | |
| 53 | | Blitz | 13 / 17 | 30 / 40 | 82 / 89 | 80 / 120 | |
| 54 | | litehtml | 19 / 24 | 37 / 42 | 107 / 128 | 92 / 188 | |
| 55 | | none (engine floor) | 14 / 17 | 30 / 47 | — | 76 / 105 | |
| 56 |
| 57 | First widget of the process, constructor / content: WebView cold **274 / 474** |
| 58 | (after installation 426 / 675), WebView prewarmed 38 / 189 plus **229 ms** of |
| 59 | the spare WebView's constructor at application start, Blitz 53 / 125, |
| 60 | litehtml 60 / 142, none 59 / 115. |
| 61 |
| 62 | Main thread over the creation of 20 widgets (sum of late time / worst frame / |
| 63 | freezes > 100 ms): WebView 700 ms / 83 / 0, prewarmed 733 / 83 / 0, Blitz |
| 64 | 183 / 33 / 0, litehtml 667 / 50 / 0, none 200 / 50 / 0. |
| 65 |
| 66 | ## Memory |
| 67 |
| 68 | PSS in MiB with 20 live widgets (dumpsys KB / 1024); the process before the first widget — 66 MiB. |
| 69 |
| 70 | | | application | renderer process | total | after destroy | |
| 71 | |---|---|---|---|---| |
| 72 | | none | 194 | — | 194 | 78 | |
| 73 | | WebView | 262 | 78 | 340 | 153 (Chromium stays in the process) | |
| 74 | | Blitz | 270 | — | 270 | 96 | |
| 75 | | litehtml | 216 | — | 216 | 90 | |
| 76 |
| 77 | Breakdown per widget: |
| 78 |
| 79 | - **Engine without a renderer: 6.3 MB** per widget ((194 − 74) / 19). The |
| 80 | widget's own QuickJS heap — 1.7 MB (median `stats.memoryBytes`); the rest is |
| 81 | the runtime, the validator context (css-tree) and two threads. This is the |
| 82 | largest item for any renderer; iOS cuts it with the validator pool |
| 83 | (`docs/chat-feed-ios.md`), Android — not yet. |
| 84 | - **WebView: ≈ 2.9 MB per widget plus ≈ 90 MB once.** In the application |
| 85 | (262 − 194) = 68 MB, of which 41 is the one-off Chromium initialisation (the |
| 86 | `prewarmed` phase: 107 vs 66), the remainder 1.4 MB per widget; in the |
| 87 | renderer process 1.5 MB per widget ((78 − 55) / 15 from the run with 5) on a |
| 88 | base of ≈ 50 MB. |
| 89 | - **Blitz: 3.8 MB per widget** ((270 − 194) / 20), of which ≈ 2.3 MB is the |
| 90 | raster Bitmap (945 px × average height 236 dp × 2.625 × 4 bytes), the |
| 91 | document itself ≈ 1.5 MB; code 12 MB once. Before this measurement the |
| 92 | prototype also held a direct buffer of the same size per widget (317 MB at |
| 93 | 20); now one scratch buffer per process. |
| 94 | - **litehtml: 1.1 MB per widget**; draws the display list straight into the |
| 95 | Canvas, holds no raster; code 6 MB. |
| 96 |
| 97 | What is missing here: `graphics` = 0 in every phase — on the emulator with the |
| 98 | host GPU the memory of WebView tiles and HWUI textures (where Blitz's Bitmaps |
| 99 | go too) is not counted. On a device both columns will grow by roughly the |
| 100 | bubble area in pixels, for WebView — in the application (the `VizWebView` |
| 101 | thread). |
| 102 |
| 103 | ## Phone: Nothing A142, Android 16 |
| 104 |
| 105 | The same APK and the same series on the phone (Android 16, WebView 154, 8 cores, |
| 106 | 11.7 GB, 420 dpi, `ANDROID_SERIAL=… TAG=phone scripts/android-bench.sh …`). The |
| 107 | main difference from the emulator: here `graphics` is counted — WebView tiles |
| 108 | and HWUI textures — and the demo's base process is already 157 MiB, of which |
| 109 | 78 is graphics. |
| 110 |
| 111 | Start-up, widgets 2–20, median / p90, ms: |
| 112 |
| 113 | | | constructor | `ready` | first content | `loaded` | |
| 114 | |---|---|---|---|---| |
| 115 | | WebView | 27 / 32 | 74 / 80 | 129 / 134 | 122 / 182 | |
| 116 | | WebView, prewarmed | 27 / 33 | 78 / 81 | 130 / 141 | 124 / 214 | |
| 117 | | Blitz | 20 / 22 | 40 / 47 | 104 / 107 | 92 / 181 | |
| 118 | | litehtml | 32 / 35 | 52 / 57 | 158 / 164 | 99 / 346 | |
| 119 | | none | 19 / 21 | 39 / 44 | — | 88 / 106 | |
| 120 |
| 121 | First widget of the process, constructor / content: WebView cold **168 / 354**, |
| 122 | prewarmed 42 / 163 with **114 ms** of the spare WebView's constructor at |
| 123 | start-up, Blitz 35 / 102, litehtml 43 / 114, none 28 / 94. Main-thread late |
| 124 | time over 20 widgets / worst frame: WebView 759 / 78, Blitz 345 / 33, litehtml |
| 125 | 1468 / 84 (layout on the CPU at 2.625×, see the per-widget windows in the report), none 314 / 34. |
| 126 |
| 127 | Memory, PSS in MiB with 20 live (`live-held`, after GC): |
| 128 |
| 129 | | | application | of which `graphics` | renderer process | total | after destroy | |
| 130 | |---|---|---|---|---|---| |
| 131 | | none | 286 | 80 | — | 286 | 281 * | |
| 132 | | WebView | 593 | 295 | 89 | 682 | 377 (graphics 202 not released) | |
| 133 | | Blitz | 425 | 141 | — | 425 | 187 | |
| 134 | | litehtml | 312 | 83 | — | 312 | 303 * | |
| 135 |
| 136 | \* in the none and litehtml runs the native heap (137 / 152 MiB) was not |
| 137 | released within 2.5 s after destroy, in the WebView and Blitz runs it was; the |
| 138 | cause was not found (the order in which the engines are stopped?), a separate item. |
| 139 |
| 140 | Per bubble on top of `none`: |
| 141 |
| 142 | - **WebView: ≈ 14 MiB plus ≈ 120 MiB once.** In the application 307 MiB, of |
| 143 | which 71 is the one-off Chromium initialisation (first widget 237 vs 166 for |
| 144 | none), the remainder ≈ 12 MiB per widget, and almost all of it is `graphics` |
| 145 | (≈ 10 MiB of tiles per 945 × ~600 px bubble); plus the renderer process |
| 146 | 89 MiB (≈ 50 base, ≈ 2 per widget). After destroying 20 WebViews the |
| 147 | application holds 377 MiB vs 281. |
| 148 | - **Blitz: ≈ 7 MiB**: the Bitmap ≈ 2.3 in the native heap, its texture ≈ 3–4 |
| 149 | in `graphics`, the document < 1. After destroy everything is released. |
| 150 | - **litehtml: ≈ 1.3 MiB**, display list into the Canvas, no raster. |
| 151 |
| 152 | The conclusions of the "What this means" section are reinforced on the phone, |
| 153 | not changed: WebView's one-off price is 168 ms and 120 MiB, per bubble it is |
| 154 | twice as expensive as Blitz and ten times as expensive as litehtml, and the |
| 155 | difference is graphics memory, which the emulator does not show. |
| 156 |
| 157 | ## Validator pool |
| 158 |
| 159 | Half of the iOS pools is ported: `ValidatorPool` (`packages/android/widget-sandbox/.../Pools.kt`), |
| 160 | `WidgetHost.Options.pools` / `sharedValidatorThread`, `TrustedValidator.background` / |
| 161 | `reset` / `sharedThread`; the test `TrustedValidatorTest.poolRecyclesAValidatorWithAFreshInstance`. |
| 162 | Validators are built ahead of time on one shared thread, the host takes a ready |
| 163 | one and hands it back with a fresh instance on destroy. Bench: `POOLS=1` |
| 164 | (4 validators at start-up, the pool refills itself between widgets; 20/20 hits). |
| 165 |
| 166 | Phone, widgets 2–20, median / p90, ms, without the pool → with the pool: |
| 167 |
| 168 | | | constructor | `ready` | first content | `loaded` | late over 20 | |
| 169 | |---|---|---|---|---|---| |
| 170 | | none | 19 → **2** | 39 → **5** | — | 88 → 63 | 314 → 155 | |
| 171 | | Blitz | 20 → **3** | 40 → **20** | 104 → **77** | 92 → 76 | 345 → 240 | |
| 172 | | WebView | 27 → 19 | 74 → 67 | 129 → 118 | 122 → 117 | 759 → 779 | |
| 173 |
| 174 | First widget of the process: none 28 / 94 → 7 / 75, Blitz 35 / 102 → 14 / 88, |
| 175 | WebView unchanged (its first widget is the Chromium initialisation). |
| 176 |
| 177 | Memory: the pool saves nothing, as was said up front. A live widget needs a |
| 178 | validator of its own; 4 idle validators cost +14 MiB (≈ 3.7 MiB each, which is |
| 179 | what building the css-tree bundle in a context costs). What it does give — |
| 180 | building the validator (~17 ms on the phone, 10–20 on the emulator) leaves the |
| 181 | main thread and the bubble's critical path, and one thread instead of a thread |
| 182 | per bubble. For the native renderers this is noticeable (content a quarter |
| 183 | earlier), for WebView it drowns in its own 50 ms to `ready`. |
| 184 |
| 185 | For the per-bubble memory to drop, the validators need **one context per |
| 186 | process with an instance per widget**: the css-tree bundle (≈ 3 MiB) is then |
| 187 | shared by all, and an instance keeps only the node model. That is a change to |
| 188 | `validator-bundle.ts` (`create` → instances by id) with a rebuild of the bundles |
| 189 | and `.qbc` on every platform, so it is not done here. |
| 190 |
| 191 | ## What this means |
| 192 |
| 193 | 1. **WebView's one-off price is real and large**: 270–430 ms of main-thread |
| 194 | blocking at the first WebView in the process plus ≈ 90 MB across two |
| 195 | processes, which do not come back after destroy (153 MB vs 78). Prewarming |
| 196 | at start-up hides the pause from the chat but pays the same 229 ms and 90 MB |
| 197 | at launch. |
| 198 | 2. **Per bubble, WebView is more expensive than a native renderer in time, not |
| 199 | in memory**: +40 ms to `ready` and +40 ms to content relative to the engine |
| 200 | floor, 4 times more main-thread late time. Blitz is indistinguishable from |
| 201 | `none` on start-up: the renderer adds nothing. |
| 202 | 3. **Per-bubble memory is decided by the engine, not the renderer**: 6.3 MB |
| 203 | of QuickJS + validator against 1–4 MB of renderer. The biggest lever on |
| 204 | Android is pooling and reusing validators, as on iOS, regardless of the |
| 205 | renderer choice. |
| 206 | 4. Blitz with a Bitmap per widget and WebView are roughly equal in PSS per |
| 207 | bubble; litehtml is three times lighter because it holds no raster. Blitz |
| 208 | can draw the same way (display list or hardware Bitmap) — that is glue, |
| 209 | not the engine. |
| 210 | 5. 20 live WebViews on the emulator did not crash and did not stutter after |
| 211 | creation; this is not an argument for "a WebView in every bubble is |
| 212 | impossible", but an argument about "the start-up pause, the one-off 90 MB |
| 213 | and a janky main thread while bubbles appear". |
| 214 | On the phone graphics memory is added to that: ≈ 10 MiB of tiles per |
| 215 | bubble, which the emulator does not show (the "Phone" section). |
| 216 |
| 217 | ## Unverified |
| 218 |
| 219 | - A weak phone. The Nothing A142 is mid-market with 8 cores; the "second" on |
| 220 | the first WebView is known from budget devices, here it is 168 ms. |
| 221 | - The native heap after destroy in the none and litehtml runs on the phone (see *). |
| 222 | - Snapshot-and-drop and the pools (iOS `WidgetHost.Options`) on Android: the |
| 223 | worst case is measured here — all 20 live. |
| 224 | - Blitz and litehtml on a device with 3× rasterisation on the CPU (here 2.625×). |
| 225 | - What happens to the WebView renderer process after the last WebView is |
| 226 | destroyed (is it alive, how much does it hold). |
| 227 |