perf(ios): read keyboard status from one keyboard snapshot

Merged
TH
11d ago
+51-24

Closes #4641

What

keyboard status on iOS read each keyboard key's label and frame as its own XCTest element query (two resolves per key, about 35 ms each across the keyboard's process boundary). On a 40-key English keyboard that made the runner command take about 1.3 s. The status read now takes one snapshot() of the keyboard element. That snapshot carries the keyboard's visibility, its frame, and every key's and button's wording and frame, so the whole read is one round trip.

The output contract (visible, returnKey, returnKeyLabel) and the return-key rule in RunnerKeyboardStatus are unchanged. The shared return-key lookup that keyboard enter and dismiss use (findKeyboardReturnControl, tapKeyboardDismissControl) is untouched. The diff is keyboardStatus and observedKeyboardKeys in RunnerTests+Keyboard.swift, one unit test, and one comment name in navigation/runtime.ts.

Where the time went

Before, one keyboard status --debug on main, from the request ndjson and the runner log:

StageBeforeAfter
daemon request total1652 ms291 ms
resolve_target_device (explicit --udid, xcrun simctl list)328 ms256 ms
runner keyboardStatus command1306 ms23 ms
XCTest queries inside the runner commandexists + frame, 2 bulk allElementsBoundByIndex, then about 80 per-element label / frame resolvesone Find the Keyboard snapshot

No waitForIdle, settle or repeated tree read was involved. The command already ran with withBoundedInteractionIdleTimeoutIfSupported(.bothSkipped). The cost was only the per-element round trips.

Timings

iPhone 17e simulator, iOS 27.0, warm daemon, keyboard up on the Wallet sign-up email field (explore-example-wallet://auth/sign-up). Wall clock per CLI call including node start, n=8 each, ms. Each run used its own private AGENT_DEVICE_STATE_DIR.

CallMain (before), --udidBranch, --udidBranch, session only
keyboard status median1612 (1498-2185)476 (430-624)232 (227-510)
snapshot median309 (298-551)320 (288-408)300 (271-421)

Raw samples, main --udid, status: 1606 1498 1845 1618 1514 2185 1884 1604. Snapshot: 551 378 309 309 304 298 309 530.
Branch --udid, status: 441 580 432 472 624 588 430 480. Snapshot: 302 295 330 310 357 408 376 288.
Branch session only, status: 510 233 240 227 228 230 231 242. Snapshot: 271 282 299 333 421 353 286 302.

The remaining gap to snapshot

With the session alone selecting the device, keyboard status costs about 0.23 s, at or below snapshot. With an explicit --udid on every call (as the T3 device wrapper passes), it is about 0.16 s over snapshot. The cause is outside the status path. resolveCommandDevice treats an explicit device selector as a fresh selection and re-reads the simulator inventory (resolve_target_device, 256 ms, cacheHit:false). snapshot goes through resolveSessionDevice and skips it. That cost applies to every command that resolves its device through resolveCommandDevice, so I left it for its own change and kept this PR on the status read path.

Output identical before and after

keyboard status --json on main and on this branch, for each state:

StateOutput (both)
name fieldvisible: true, returnKey: next, returnKeyLabel: next
email fieldvisible: true, returnKey: next, returnKeyLabel: next
password fieldvisible: true, returnKey: done, returnKeyLabel: done
keyboard hidden (after keyboard enter on the password field)visible: false

Verification

  • Device: iPhone 17e simulator, iOS 27.0, F25C7515-D67E-4838-BEAC-0AD08DB056EC.
  • Measured source: main 1cb2f242ae (before) and this branch with the same runner change at the head before the unit test and formatting pass was added. The runner was rebuilt with pnpm build:xcuitest:ios.
  • New unit test: testObservedKeyboardKeysReadsKeysThenButtonsFromOneKeyboardSnapshot (iOS only, nightly lane). It checks nested descendants, keys before buttons, the whitespace-only space bar kept, and label-less or non-key elements dropped.
  • pnpm check:xctest-selection passes locally. Per the worktree rules, CI validates the rest.

šŸ¤– Generated with Claude Code