Skip to content

feat(mobile): boot the next shell page while the current one is idle - #32204

Open
Jinwoo-H wants to merge 4 commits into
jinwoo/wv-spare-2-poolfrom
jinwoo/wv-spare-3-refill
Open

Jinwoo-H wants to merge 4 commits into
jinwoo/wv-spare-2-poolfrom
jinwoo/wv-spare-3-refill

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​334 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​326
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​153 $\color{#cf222e}{\Huge{\mathbf{−}}}$​42 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​111

Summary

When a shell screen has painted and is idle, the phone boots the next page in the background, so the next host to session open reuses it instead of starting a new WebView. On iOS this removes the per-view web process start.

  • useSparePageRefill prepares a spare 1 s after paint while the screen is focused and the app is active, and only when the screen shows the host's current generation (a screen left behind by an update would boot from a deleted tree and evict the good spare). It skips screens whose page owns the host area.
  • Opening a page generation takes the spare's session id when the pool has a matching page, and mints a new id otherwise (or when the pool refuses). Without the pool the id is minted in the same tick, as today.
  • Spares are discarded when the page cache is deleted, when a new page generation is committed, and when a host is removed.
  • The bridge asks the view to replay an adopted page's ready frame once the host is built.
  • On binaries without the native pool, OrcaMobileWebShellSpares is null and every path above is skipped.

Numbers

Host screen to session screen, tap to painted, median, release builds, interleaved per cycle, base vs spare.

Platform n per arm Base Spare Change
Android emulator, API 36 19 1049 ms 817 ms -232 ms
iOS 26.5 simulator 6 2287 ms 812 ms -1475 ms

On Android, tap to page init drops from 451 ms to 204 ms. On iOS, the base spends about 945 ms between loading the URL and the page starting, which is the new WebView's web process starting; the spare has already paid it. First-open noise between runs is about 100 to 200 ms.

Galaxy S24

Pending: base vs spare on a Galaxy S24, interleaved, at least 8 cycles per arm, same 4 s wait. Results will be added here.

Method

Release builds of this stack and of its base, with the start-up timing marks, against a source-built desktop serving the same page bundle. Each cycle opens the host screen, waits 4 s, taps into a session and reads tap, init and painted marks from the log; the arms alternate every cycle. The spare is not used by the first open after launch, only by the next screen, which is what the refill targets.

Simulator vs device

Emulator and simulator numbers show direction, not size. The iOS gain is large because the simulator's web process start is slow; on a device the start is cheaper, and the spare's memory cost (one extra WebView while idle) matters more. The Galaxy S24 run above, once done, will size Android on a device; iOS device memory is on the release checklist.

Checks

Mobile vitest, typecheck and lint pass. Release builds, device-check flows on the Android emulator (API 36) and the iOS 26.5 and 18.1 simulators: first open, host to session, New Workspace overlay, pop to an existing screen (#32110), renderer kill then remount, background then foreground, new page generation from a desktop update, host removal and re-pair. On iOS, taps where the parked spare sits under the host page reach the host page.

Flow Android emulator API 36 iOS 26.5 simulator iOS 18.1 simulator
First open pass pass pass
Host to session pass pass pass
New Workspace overlay pass pass pass
Pop to an existing screen (#32110) pass pass pass
Renderer kill then remount pass pass pass
Background then foreground pass pass pass
New page generation from a desktop update pass pass pass
Host removal and re-pair pass pass pass
Taps on the host page with the parked spare beneath it n/a (spare is detached) pass pass
This JS on main's native code (no pool), every flow above pass pass pass

On the iOS 18.1 simulator the spare's presence was confirmed from the window's view tree: with this stack the window holds the parked WKWebView at index 0 with user interaction off plus the host page's WKWebView; without it, only the host page's.

After review fixes, on test-only builds that log the pool (not committed): an update followed by a return to a screen on the old generation boots nothing from the old tree, and the next session adopts the spare booted from the new one (Android emulator; on iOS 26.5 the shell's controls never refocus an older shell screen, so there the spare booted after the update was checked to be adopted by the next host open). A spare claimed but not yet adopted is destroyed by host removal (Android) and by backgrounding (iOS 26.5), and the screen comes back live.

Compat

New JS on a binary without the native pool takes today's path: it never calls the pool and mints session ids as before. Checked by running this JS on main's native code through every flow above. The page bundle is unchanged.

Jinwoo-H and others added 4 commits October 23, 2026 00:50
A shell screen that opens a new WebView (host page to session, the New
Workspace overlay) used to build it, load the document and run 1.36 MB of
entry code after the tap. Now, one second after a shell page paints and
while its screen is focused in a foreground app, the screen asks the native
pool to boot one page for its host from the same generation. The next
screen that opens that generation takes the parked page's session id and
adopts it, so only the route's own code and the first paint are left.

- Feature-detected: on a binary without the pool OrcaMobileWebShellSpares
  is null, the runtime has no spares, and every open mints its own id and
  builds its own WebView as before.
- Skipped when the page owns the host area: its screens open inside it.
- A spare booted from a generation is dropped when that generation is
  deleted (download commit, delete-and-refetch) and when its host is
  removed. A remount always mints a fresh id.
- After building the bridge host, the hook asks the view to replay the
  adopted page's ready, in case it arrived before the host existed.

Co-Authored-By: Claude <[email protected]>
# Conflicts:
#	mobile/src/mobile-web-shell/mobile-web-shell-session-effects.test.ts
#	mobile/src/mobile-web-shell/use-mobile-web-shell-bridge.ts
#	mobile/src/mobile-web-shell/use-mobile-web-shell-session.test.ts
#	mobile/src/mobile-web-shell/use-mobile-web-shell-session.ts
#	mobile/src/transport/host-removal-lifecycle.test.ts
AmoabaKelvin added a commit that referenced this pull request Nov 9, 2026
While native Home is on screen, boot one page document for the most
recently connected host with a cached build, parked invisibly in the
window. Opening a page from that build adopts it instead of building a
WebView, which removes the WebView start and script parse from the tap.

The spare is dropped when Home is left without a claim (2 s grace), on
background, memory pressure, its own failure and before the cache deletes
its files. It is never kept beside a shown page, and only phones with
more than 3 GiB of RAM (4 GB phones) get one. A parked page is told to
stop asking for init; the adopting view answers the ready it sent.

Builds on Jinwoo's spare pool and replay work in #32203 and #32204.

Co-authored-by: Jinwoo-H <[email protected]>
AmoabaKelvin added a commit that referenced this pull request Nov 9, 2026
…skips the WebView start (#40018)

* perf(mobile): answer a page's ready that arrived before its bridge host

A page's ready can reach the shell before the screen has built its bridge
host (the host waits on the client and the host profile read). It used to
be dropped, so init waited for the page's next retry, up to 2 s later.
Keep the latest ready per session and answer it once the host exists.

* perf(mobile): keep one prewarmed page document while Home is shown

While native Home is on screen, boot one page document for the most
recently connected host with a cached build, parked invisibly in the
window. Opening a page from that build adopts it instead of building a
WebView, which removes the WebView start and script parse from the tap.

The spare is dropped when Home is left without a claim (2 s grace), on
background, memory pressure, its own failure and before the cache deletes
its files. It is never kept beside a shown page, and only phones with
more than 3 GiB of RAM (4 GB phones) get one. A parked page is told to
stop asking for init; the adopting view answers the ready it sent.

Builds on Jinwoo's spare pool and replay work in #32203 and #32204.

Co-authored-by: Jinwoo-H <[email protected]>

* fix(mobile): unregister the shell's memory callbacks from the context that registered them

---------

Co-authored-by: Jinwoo-H <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant