Skip to content

feat(mobile): native pool for one page booted ahead of its screen - #32203

Open
Jinwoo-H wants to merge 4 commits into
jinwoo/wv-spare-1-page-splitfrom
jinwoo/wv-spare-2-pool
Open

Jinwoo-H wants to merge 4 commits into
jinwoo/wv-spare-1-page-splitfrom
jinwoo/wv-spare-2-pool

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​89 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​88
Prod 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​723 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​714

Summary

Adds a native pool that can hold one shell page booted ahead of its screen. Nothing calls it yet (the JS that does is the next PR), so this PR is inert.

  • prepareSpare(hostKey, directory, sessionId) boots a page under a session id and parks it. There is one spare app-wide; a new prepare replaces it.
  • takeSpare(hostKey, directory) hands its session id to a screen that is about to open. The view that receives that id adopts the page instead of creating one. An unadopted claim is destroyed after 10 s.
  • While parked, the page's load states and last bridge frame are recorded and replayed into the view on adoption. The view re-sends the adopted ready frame (replayPageReady) until JS first posts to the page, so the JS bridge sees the same sequence as a fresh page.
  • A session id is only ever loaded by one WebView. Every view records the id it loads, so a spare is never parked under an id already on screen. If a view gets an issued id whose page is gone, it reports render-process-gone so the screen remounts with a fresh id, which is the existing recovery path.
  • Teardown: memory pressure (Android onTrimMemory at RUNNING_LOW or worse, iOS memory warning), app background, activity or module destroy, renderer death, and discardSpares(hostKey?). Discarding a host destroys its parked and claimed spares; a view about to adopt a destroyed claim takes the remount path above. Teardown always runs on the main thread (Android's module OnDestroy can run off it, so it posts).
  • Parking: Android keeps the spare detached and lays it out by hand at the window size. iOS parks it in the key window beneath the root view with touches and accessibility off; off-window WKWebViews defer the GPU process, which cost about 1.8 s on adoption in testing.
  • The slot state machine is pure and generic (MobileWebShellSpareSlots), with Kotlin unit tests and Swift checks for park, take, adopt, expire, reuse refusal and discard.
  • JS: OrcaMobileWebShellSpares is the optional native module, or null on binaries without it.

Checks

Kotlin unit tests (MobileWebShellSpareSlotsTest) and Swift checks (tests/MobileWebShellChecks.swift) 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.

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

Compat

Additive native functions. JS feature-detects the module, so new JS on older binaries does nothing new. No change to props, events, bridge protocol or the page bundle.

Jinwoo-H and others added 4 commits October 23, 2026 00:39
Adds the native half of a spare page: the module can boot one shell page
for a host and generation before any screen asks for it, hand its session
id out once, and let the next view rendered with that id adopt the page
instead of building one. Nothing calls it yet, so behaviour is unchanged.

- prepareSpare / takeSpare / discardSpares on the module, and a
  replayPageReady view function. JS sees them through
  OrcaMobileWebShellSpares, which is null on binaries without them.
- One spare app-wide. Every fence is installed by the same page code at
  boot. A session id is loaded by one WebView ever: a taken spare leaves
  the pool before its id is returned, and an issued id whose page is gone
  makes the view report render-process-gone, so the session remounts with
  a fresh id.
- Adoption replays what the parked page reported (load states and its
  last ready), so the session sees the same sequence as a fresh view and
  does not wait out the page's 2 s ready backoff.
- Teardown: memory pressure, app backgrounded, activity or module
  destroyed, a claimed spare not adopted within 10 s, and a dead renderer.
- Android parks the WebView detached, laid out at the window size. iOS
  parks it in the key window beneath the app with touches and
  accessibility off: off-window WebKit defers its GPU process to the first
  shown view, which stalled a first open by ~1.8 s on the simulator.
- The slot rules are pure and checked on both platforms.

Co-Authored-By: Claude <[email protected]>
# Conflicts:
#	mobile/modules/orca-mobile-web-shell/ios/MobileWebShellPage.swift
# Conflicts:
#	mobile/modules/orca-mobile-web-shell/android/src/main/java/expo/modules/orcamobilewebshell/MobileWebShellPage.kt
#	mobile/modules/orca-mobile-web-shell/ios/MobileWebShellPage.swift
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