Skip to content

feat(scripts): mobile:metrics benchmarks thread switches, tabs and memory on pool devices - #42975

Open
juliusmarminge wants to merge 14 commits into
mainfrom
t3/mobile-metrics
Open

juliusmarminge wants to merge 14 commits into
mainfrom
t3/mobile-metrics

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Problem

Nothing measured the mobile app's thread switching, tab switching or memory. mobile:behavior checks that flows work, not how fast they are, and #42606 covers only the web client.

Change

vp run mobile:metrics runs on mobile:behavior's stack: it leases a Simlock device, installs the cached build, pairs it with a seeded server and drives it with agent-device. Its seed and fake GitHub are shared with client-metrics. Lease and session handling moved into scripts/mobile-behavior/{session,pool}.ts, so both runners share it. Every lease is released when setup fails, and also on a crash.

Cases

  • Thread switches: switch-short, switch-long and switch-working, first visits and revisits measured separately.
  • Tabs: PRs, Usage and Chats.
  • PRs and issues: pull-request (list and details) and issues.
  • Thread views: diff (Review changes) and side-chat.
  • Input: type and scroll-long.

What it measures

The behavior probe (behavior-probe.ts) records:

  • Content: the time from the touch to the first frame that shows the target's rows.
  • Settled: the last React commit before a second of quiet.
  • commit count and commit time;
  • dropped JS and UI frames.

Native menu items (Review changes, the issues switcher) never pass the touch to JS, so their timing starts at the item's JS handler.

--soak <n> repeats the switch cases and samples the Hermes heap after a forced gc(). It also records registry atoms and mounted fibers to soak-retention.ndjson, so you can tell a retained-object leak from a growing tree.

--build dev|release

The pool installs only the dev client. --build dev (default) runs the development bundle. --build release starts Metro with --no-dev and puts a proxy in front of it (release-bytecode.ts) that serves the production bundle compiled with the checkout's hermesc -O. Everything else, inspector sockets included, passes through, so the same dev client runs release bytecode. Compiling takes a few minutes per app launch.

  • Probe: gated on EXPO_PUBLIC_T3_BEHAVIOR_PROBE alone, not __DEV__. Store builds inline the unset flag, so Metro still strips it: a production expo export has no probe code. In production bundles it stubs React's DevTools hook so commits still reach it.
  • Pairing links: prefill and autoConnect=1 are allowed in __DEV__ or with that same flag, so only the benchmark's bundle gains them.
  • Not measured in release: commit ms (React's profiling fields), --renders (rejected), and readable component names in soak retention (minified).
  • ab and compare treat build as part of the workload, so dev and release results never compare.

Home rows are now pressed by snapshot ref: a row's label ends in a relative time ("Bench short, 4m") that could tick between reading the screen and the press.

Docs: the "Mobile switch metrics" section of 16_performance-regressions.md.

Scope

The maintainer asked for this as the mobile counterpart of #42606, for iterating on mobile thread-switch performance. It is maintainer dev tooling plus probe hooks gated on a flag only the harness sets. Store builds are unchanged.

Verification

  • vp test run scripts/mobile-metrics/report.test.ts covers the report math; devAutoConnect.test.ts covers the pairing gate in a production bundle with and without the flag.
  • A production iOS expo export without the flag contains none of the probe's names.
  • A full dev-build run with all cases and 2 rounds ran on an iPhone 18 Pro simulator from the pool. Every case passed in both rounds.
case (dev build) content p50 settled p50 JS dropped
switch-short, first / revisit 1259 / 448 ms 2772 / 1646 ms 35 / 2%
switch-long, first / revisit 865 / 853 ms 2352 / 1861 ms 26 / 1%
switch-working, first / revisit 894 / 723 ms 2177 / 2026 ms 29 / 4%
pull-request: list / details – 86 / 1916 ms 1 / 34%
diff – 1828 ms 19%
side-chat, first / revisit 615 / 499 ms 1656 / 1672 ms 20 / 2%
type, per key 13.7 ms – 1%
  • --build release --cases switches --rounds 3 --soak 12 on an iPhone 18 Pro:
case (release) content p50 settled p50 JS dropped
switch-short, first / revisit 365 / 134 ms 1479 / 1587 ms 9.8 / 3.4%
switch-long, first / revisit 432 / 274 ms 1575 / 1570 ms 9 / 1%
switch-working, first / revisit 310 / 245 ms 1777 / 1574 ms 10.8 / 7.6%

Soak: dev growth is dev-only, release is flat

A dev-build --soak grows the Hermes heap about 5 MB per iteration. That growth is all dev machinery:

  • the React DevTools backend;
  • the dev client's debugger-enabled Hermes keeping closure locals alive;
  • react-refresh and React 19's dev debug stacks.

In release mode the heap settles and stays flat. Over 12 iterations it went 124, 116, 108, 100, then 92 MB from iteration 4 through 12: 0 MB per iteration over the last half. A rerun on the pushed head with --soak 6 settled at 88–92 MB the same way. Soak in release.

Not covered:

  • Android runs;
  • the time from the finger to the JS handler for native menus.

Stacked on #42606.

Model and harness: Claude Opus 5.5 in Claude Code (via T3 Code).

🤖 Generated with Claude Code

juliusmarminge and others added 13 commits November 24, 2026 19:50
… client memory

Nothing measured client wall-clock, CPU or memory in the real app, while a desktop trace showed
thread switches costing 110-330 ms, mostly forced layout, timeline/composer rebuilds and the
right panel.

`vp run report:client` builds the web app for production, serves it from a server on an
isolated base dir seeded through the CLI with replayed threads (two new dev-replay recordings:
a heavy turn and a long stream), a branch with a 40-file diff and a pull request on the fake
GitHub, which now also answers activity, file stats and the REST files list. Headless Chromium
switches threads by real sidebar clicks and records click-to-paint, first-frame content, long
animation frames, heap/DOM after GC, renderer CPU while a thread streams, and with --trace the
forced style/layout call sites mapped through sourcemaps. `ab` alternates two checkouts and
`compare` gates the medians, reusing server-metrics' A/B rounds and machine watch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d CPU by source

Switches alone missed regressions in typing, scrolling, the palette, panel
tabs, the terminal and Settings, and timing noise hid small render
regressions.

- Interaction cases, selectable with --cases (or the switches/interactions
  groups): composer typing on a short and a long thread, wheel-scrolling the
  long timeline, the command palette, PR panel tabs, switching between two
  surfaces, the terminal drawer, and Settings and back. Each step records
  input-to-paint, LoAF and missed frames.
- --renders counts React commits and component renders per step with their
  top components and causes; --slot-diff deep-diffs named components' hook
  slots; --unminified builds with readable names. compare gates on renders.
- --trace now carries a CPU profile: per marked step, the input task's
  forced style/layout, self time by package, inclusive time by source file
  and library (once per sample), and the long tasks that follow.
- Panel surfaces record their DOM size, with a census in the artifacts.
- --soak repeats every case and fits heap/DOM/listener growth.
- noise derives per-metric floors from A/A runs; compare/ab --floors use them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s and floors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sub-16 ms paints count as 16 ms instead of dropping out of comparisons; result
files record their workload and compare refuses mismatched ones. Switch
timings start at the page's own click timestamp, long frames are clipped to
the window, and a switch that does not reach its thread fails the run. The
working-thread CPU windows are dropped once the replayed turn has finished.
Seeding errors no longer echo process output or the pairing token. The fake
GitHub refuses the diff media type with 406, as GitHub does for large diffs.
Slot diffs show deleted Map keys, anonymous components count, and --cases
rejects inherited names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compare takes each run's median as one sample and gates only with two or more
runs a side, so one page's samples never pass for independent runs. The trace
reports the median of each window's forced total, never borrows a worker's
profile, and counts only long tasks after the input task. A failed step stops
its frame loop and render probe, and its render readings and traced windows
are dropped. A panel that cannot open skips only the cases that need it.
Event Timing and long-frame entries are kept only while a measurement watches,
so soak heap samples hold none. noise refuses A/A pairs whose probe or build
settings differ.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…content by paint

Thread ids like `mcp:<uuid>` are percent-encoded in the route, so the new
route checks decode it. Content time reads the clock when the frame's
callback runs: a frame's begin time can precede the click whose long task
delayed it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m through

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ns after palette

A soak's heap kept growing ~1 MB per iteration for dozens of iterations, which
the verdict called a leak. Heap snapshots showed it was V8 compiled code while
app objects stayed flat. The soak now runs in a second pass whose Chromium has
V8's compiling tiers off (timing runs are untouched), and the verdict fits only
the soak's later half, where warm-up has settled and a leak keeps its rate.

The terminal case was skipped in every combined run: the palette case pressed
Escape and waited a fixed 400 ms, and chat shortcuts ignore keys while the
palette is still mounted (closing animation included), so Ctrl+J was dropped.
The palette case now waits until the palette unmounts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cases leave no call sites

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…avior's stack

Maintainers had a web client benchmark but nothing to measure the React Native app's thread
switching or other interactions.

`vp run mobile:metrics` (run, ab, compare, noise, summary) leases a Simlock iOS simulator and
reuses mobile:behavior's server, Metro and dev-only probe, now shared through
mobile-behavior/session.ts and pool.ts. The probe gains a perf window: JS-side touches, React
commits, the commit that first shows a thread's rows (a mark in ThreadFeed), composer keys,
JS/UI frames and the Hermes heap, with the render counter for --renders. Cases cover thread
switches (short, long, working; first visit and revisit), tabs, the PR list and details on the
fake GitHub with client-metrics' 40-file branch, issues, a thread's review sheet, side chats,
typing and scrolling. compare/noise reuse client-metrics' bootstrap gate and floors through new
series-level helpers. It measures a development build, so counts and A/B differences are
representative and absolute times are not.

Also fixes the fake GitHub proxy crashing its harness when a refused client resets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aks switches, and releases leases on crash

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…etries failed cases each round

The issues switcher is a native menu trigger agent-device will not tap by ref, so it is tapped at
its labelled view's centre. A failed case no longer drops its later rounds, back tolerates UIKit's
unknown outcome mid-pop, and heap samples follow Hermes' own gc().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… fibers

Each soak sample also writes the atom registry's nodes by label and mounted fibers by component to
soak-retention.ndjson, so heap growth can be told apart from atoms or a growing mounted tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XXL 1,000+ changed lines (additions + deletions). labels Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire — 5.0 KiB — 6.8 KiB ✅
Codex Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅
Codex Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Codex Live turn WebSocket decoded — 21.5 KiB — 24.4 KiB ✅
Codex Live turn messages — 1 — 8 ✅
Claude Total thread wire — 5.0 KiB — 6.8 KiB ✅
Claude Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅
Claude Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Claude Live turn WebSocket decoded — 21.9 KiB — 24.4 KiB ✅
Claude Live turn messages — 1 — 8 ✅

Other scenarios

No main baseline exists yet for these 64 scenario measurements.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded — 10.5 KiB — 12.7 KiB ✅
Codex short turn resume WebSocket messages — 2 — 2 ✅
Codex long turn running, cold open HTTP decoded — 281.7 KiB — 302.7 KiB ✅
Codex long turn running, cold open rows — 75 — 75 ✅
Codex long turn running, history page HTTP decoded — 92.4 KiB — 107.4 KiB ✅
Codex long turn running, history page rows — 75 — 75 ✅
Codex long turn finished, cold open HTTP decoded — 381.5 KiB — 410.2 KiB ✅
Codex long turn finished, cold open rows — 151 — 151 ✅
Codex long turn finished, socket cold open WebSocket decoded — 381.6 KiB — 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages — 2 — 2 ✅
Codex long turn finished, socket cold open rows — 151 — 151 ✅
Codex long turn finished, work page HTTP decoded — 186.2 KiB — 200.2 KiB ✅
Codex long turn finished, work page rows — 150 — 150 ✅
Codex idle thread resume WebSocket decoded — 65 B — 200 B ✅
Codex idle thread resume WebSocket messages — 1 — 1 ✅
Codex fleet shell snapshot HTTP decoded — 42.4 KiB — 53.7 KiB ✅
Codex fleet shell snapshot rows — 27 — 27 ✅
Codex fleet shell subscribe WebSocket decoded — 65 B — 200 B ✅
Codex fleet shell subscribe WebSocket messages — 1 — 1 ✅
Codex fleet shell resume check HTTP decoded — 18 B — 100 B ✅
Codex fleet shell resume check rows — 0 — 0 ✅
Codex stale shell reload HTTP decoded — 42.4 KiB — 53.7 KiB ✅
Codex stale shell reload rows — 27 — 27 ✅
Codex stale shell resume WebSocket decoded — 140 B — 400 B ✅
Codex stale shell resume WebSocket messages — 2 — 2 ✅
Codex stale todo list cold open HTTP decoded — 72.4 KiB — 83.0 KiB ✅
Codex stale todo list cold open rows — 75 — 75 ✅
Codex stale todo list cold open nodes — 2 — 4 ✅
Codex stale todo list cold open subagents — 2 — 4 ✅
Codex stale todo list cold open plans — 1 — 2 ✅
Codex stale todo list cold open providerTurns — 1 — 2 ✅
Codex stale todo list cold open checkpoints — 1 — 2 ✅
Claude short turn resume WebSocket decoded — 10.6 KiB — 12.7 KiB ✅
Claude short turn resume WebSocket messages — 2 — 2 ✅
Claude long turn running, cold open HTTP decoded — 283.3 KiB — 302.7 KiB ✅
Claude long turn running, cold open rows — 75 — 75 ✅
Claude long turn running, history page HTTP decoded — 93.4 KiB — 107.4 KiB ✅
Claude long turn running, history page rows — 75 — 75 ✅
Claude long turn finished, cold open HTTP decoded — 384.2 KiB — 410.2 KiB ✅
Claude long turn finished, cold open rows — 151 — 151 ✅
Claude long turn finished, socket cold open WebSocket decoded — 384.3 KiB — 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages — 2 — 2 ✅
Claude long turn finished, socket cold open rows — 151 — 151 ✅
Claude long turn finished, work page HTTP decoded — 188.1 KiB — 200.2 KiB ✅
Claude long turn finished, work page rows — 150 — 150 ✅
Claude idle thread resume WebSocket decoded — 66 B — 200 B ✅
Claude idle thread resume WebSocket messages — 1 — 1 ✅
Claude fleet shell snapshot HTTP decoded — 43.0 KiB — 53.7 KiB ✅
Claude fleet shell snapshot rows — 27 — 27 ✅
Claude fleet shell subscribe WebSocket decoded — 66 B — 200 B ✅
Claude fleet shell subscribe WebSocket messages — 1 — 1 ✅
Claude fleet shell resume check HTTP decoded — 18 B — 100 B ✅
Claude fleet shell resume check rows — 0 — 0 ✅
Claude stale shell reload HTTP decoded — 43.0 KiB — 53.7 KiB ✅
Claude stale shell reload rows — 27 — 27 ✅
Claude stale shell resume WebSocket decoded — 140 B — 400 B ✅
Claude stale shell resume WebSocket messages — 2 — 2 ✅
Claude stale todo list cold open HTTP decoded — 73.4 KiB — 83.0 KiB ✅
Claude stale todo list cold open rows — 75 — 75 ✅
Claude stale todo list cold open nodes — 2 — 4 ✅
Claude stale todo list cold open subagents — 2 — 4 ✅
Claude stale todo list cold open plans — 1 — 2 ✅
Claude stale todo list cold open providerTurns — 1 — 2 ✅
Claude stale todo list cold open checkpoints — 1 — 2 ✅

Baseline: unavailable · PR result: cdb607b · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

…e on the dev client

The dev build's soak reported about 5 MB of heap growth per iteration that was all dev
machinery (the DevTools backend, debugger-enabled Hermes keeping closure locals alive,
react-refresh, React's dev debug stacks), and its timings are not representative.

`--build release` starts Metro with --no-dev and puts a proxy in front of it that serves the
production bundle compiled with the checkout's `hermesc -O`; everything else, inspector
sockets included, passes through. The behavior probe is now gated on its env flag alone (store
builds inline it unset, so Metro still strips the probe) and stubs React's DevTools hook in
production so commits still reach it. Pairing-link prefill and auto-connect allow that same
flag, so only the benchmark's bundle gains them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from t3/client-metrics-benchmark to main November 25, 2026 19:59

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

size:XXL 1,000+ changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant