Skip to content

perf(mobile): WAL index scales with changes, live transcript/Tasks first build, device perf harness - #23859

Merged
Git-on-my-level merged 23 commits into
mainfrom
lane/iphone-perf
Oct 28, 2026
Merged

Git-on-my-level merged 23 commits into
mainfrom
lane/iphone-perf

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Why

A heavy phone (iPhone 15 Pro Max) logged 133 main-isolate stalls over about 10 hours. Its WAL index held 71,536 records, 66,222 of them synced.

  • Severity: 24 s blocked in total; p50 139 ms; worst 1.6 s.
  • Where: 75 of the 133 happened on idle Home.
  • When: about 20x more often than chance in the 1.5 s after a sync phase or upload. One reconnect burst blocked for 5.5 s.

The device harness measured only drawn frames, used a 6,500-record fixture, and never saw any of this.

What

App: WAL index work now scales with what changed (perf(sync), plus the fix(sync) round from review)

  • Saves: a long-lived index worker receives only changed rows; durable is acknowledged only after flush and rename. Loading runs off the main isolate, and the worker seeds unchanged rows itself.
  • Format: the version-1 wals.json format, backup and quarantine handling are unchanged.
  • Views: SyncProvider exposes incremental derived views for Home, On the Way and Device Settings.
  • Reconcile: passes join a running pass and are spaced at least 20 s apart.
  • Failure handling: a dead worker, a corrupt main index that couldn't be quarantined, and repair-path writes all fail closed and recover within the session.
  • Kill switch: PostHog mobile-wal-delta-index-off (ops_kill, default false, registered in config/feature-flags.yaml). True makes the next launch save through the pre-delta full-snapshot writer; both writers produce the same file, so either flip needs no migration. Read once per launch with a 1 s bound; offline or failed reads keep the delta writer on.

App: live transcript and Tasks (perf(mobile) x2, plus the fix(mobile) round from review)

  • Opening the transcript anchors at the newest rows. A 1,000-segment open builds about one screen of rows (measured: 153 ms layout and 1,775 builds; RSS peak 612 MB). Short transcripts render on the first frame.
  • Rows the reader is looking at stay put when rows above them grow, at rest, during a drag or during a fling.
  • Preview revisions reuse the prepared final spans (main's settled-tail coverage, prepared once per final snapshot) and don't rebuild the transcript.
  • The first Tasks switch builds offscreen sections lazily (measured: 240–319 ms frame).
  • The live row computes the uncovered preview once per clock tick.

Harness (test(mobile-perf), plus the fix(mobile-perf) rounds)

  • Three new windows: home_live_preview, live_episode_page and device_settings_on_the_way.
  • A new idle window, home_idle_sync_refresh.
  • Every window reports main-isolate stalls (HeavyStallProbe).
  • --synced-wals N runs a field-shaped diagnostic; it is never eligible as a baseline.
  • The runner refuses a phone that isn't on a wired USB connection, before building.
  • Fixed: macOS bash 3.2 aborted every physical iOS batch on an empty array.
  • Fixed: iOS 27 negative frame totals (total is now measured from the earlier of vsync and build start). This changes the total metric, so a new baseline must be qualified.

Review

  • Two independent GLM reviews (zai/glm-5.3) covered the UI diff and the WAL diff.
  • UI findings fixed: misplaced first frames on short transcripts; content shifting under a gesture.
  • WAL findings fixed: worker death wedging saves; seeding from a corrupt main index after loading from backup; repair writes racing the worker.
  • The WAL review also verified the mainstream path: dirty tracking for every persisted field, bucket moves, ack after rename, format compatibility, derived-view parity and reconcile spacing.

Evidence

  • flutter test --no-pub test/services test/providers test/unit test/pages test/perf test/widgets test/spine: 7,327 passed, 4 skipped, 0 failed (merged head).
  • Changed files analyze clean.
  • Python perf tools: 43 tests passed.
  • Device, iPhone 15 Pro Max, profile build, field-shaped index (--synced-wals 65000), 3 runs before vs 3 after. Main-isolate blocked time over 100 ms per run:
    • cold_start: 794/738/905 ms to 273/287/323 ms (p90 132 to 12.9 ms).
    • live_episode_page: 142/151/141 to 0/0/0.
    • home_live_preview: 144/124/154 to 0/0/0.
    • wal_sync_bg_fg: 144/255/251 to 0/133/114.
    • open_conversation: regressed to 223/257/116, then 0 after the bounded scroll-reporting fix.
    • First Tasks switch (~300 ms): unchanged. The widget-named trace shows a 302 ms young-gen GC scavenge on that tap (heap shape from ~71k resident WAL objects), not Tasks UI work; follow-up.
  • Final standard batch (6,500 WALs, 7e66b38): 7 of 9 windows within 15% p90 spread. cold_start and the idle sync window draw too few frames for a stable p90, so the batch fails variance and is not an accepted baseline. All windows except tab_switch have 0 stalls over 100 ms.
  • test/unit/knowledge_graph_prebuild_test.dart failed once under full-suite load and passes 3/3 in isolation on this branch and on the untouched tree (no knowledge-graph code changed).
  • Receipts: /Volumes/scratch/mobile-heavy-profile/2026-10-28-* (scratch, not committed).

UI-Evidence: none -- no visual change intended; transcript, Tasks and the live row render the same layout, with laziness, anchoring and caching changes only

Product invariants affected

  • INV-CAP-1 (pendant audio retention): the WAL index that records durable audio now persists deltas through a worker. Retention, admission and upload policy are unchanged; an index save is acknowledged durable only after flush + atomic rename, exactly as before; the mobile-wal-delta-index-off kill switch restores the previous full-snapshot writer without a release; worker death, unseedable index and repair writes fail closed (no false durable ack) and recover in-session without losing admitted deltas. No capture, uplink or frame path changed.

Failure class (fixes)

Failure-Class: none

🤖 Generated with Claude Code

Git-on-my-level and others added 15 commits October 28, 2026 14:24
…aunch

HOST_GUARD is empty on every physical-device run, and macOS /usr/bin/env bash
(3.2) treats "${HOST_GUARD[@]}" of an empty array as unbound under set -u, so
every physical iPhone batch failed before receipt 1. Expand it only when set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On an iPhone 15 Pro Max (iOS 27.0.1) about one frame in seven starts building
~0.85 ms before its recorded vsync, so FrameTiming.totalSpan (raster finish -
vsync) is negative. Total p50/p90 were contaminated in every window, and
cold_start's p50 went negative, failing report validation for every batch.
Measure total from the earlier of vsync and build start. This changes the total
metric: earlier total percentiles are not comparable; qualify a new baseline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the Way windows

Three heavy-profile windows after the unchanged five, for the changes in
#23819, #23822 and #23853:

- home_live_preview: Home with the live episode row while a scripted on-device
  preview revises its newest line every 200 ms over a ~1,000-segment session
  (LivePreviewCoverage on every update and clock tick).
- live_episode_page: LiveEpisodePage on the transcript tab over the same
  session, scrolled while words arrive.
- device_settings_on_the_way: Device Settings (Catching up) and On the Way
  (day-grouped) over the 6,500-WAL backlog, each opened and scrolled.

The preview controller is installed through CaptureController.installLivePreview
and admitted through LivePreviewController.admit; only the socket admission flag
is asserted, since the fixture runs no listen socket. Device Settings gets an
interface fake: the production DeviceProvider subscribes to ServiceManager,
which this harness never initializes. Reports now require the eight windows;
comparisons list windows absent from the reference instead of failing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… idle sync window

The field lag log that matters (iPhone 15 Pro Max, 10-26) is 133 main-isolate
stalls, mostly on idle Home and around sync phases, with a 71,536-record WAL
index. Drawn-frame timings could not see any of it.

- HeavyStallProbe: every window reports stalls over 50/100 ms, blocked time and
  the worst stall from a 20 ms timer's late ticks; reported, never variance-gated.
- --synced-wals N (0..80000): adds synced history on top of the pending
  backlog; such a batch changes the dataset and is never baseline-eligible.
- home_idle_sync_refresh: Home left alone while SyncProvider refreshes the
  inventory five times, as sync phase ends and upload callbacks do.
- Runner preflight: refuses a phone that is not on a wired USB connection
  before the multi-minute build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Semantics label called previewText() twice per 1 s rebuild; each call runs
LivePreviewCoverage.uncovered over every final segment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rame stays cheap

Measured on an iPhone 15 Pro Max (heavy profile harness):
- Opening LiveEpisodePage on the transcript tab took one 153 ms layout with
  1,775 builds (140-157 ms every run) and peaked RSS at 612 MB: following the
  latest jumped to maxScrollExtent on a variable-height lazy list, laying out
  every row. TranscriptWidget now anchors layout at the newest segment; a
  1,000-segment open builds 9 rows and lands on the newest.
- Preview revisions (every ~200 ms) no longer rebuild the transcript or rescan
  final history: LivePreviewCoverage prepares merged final spans once per
  transcript snapshot and answers each line by binary search, same results.
- The first Tasks tab switch spent 128 ms in one build (240-319 ms frame):
  ActionItemsPage now uses one lazy delegate across date sections, deferring
  offscreen sorting, headers and rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ecord ever kept

A heavy phone's index held 71,536 records (66,222 synced). Its lag watchdog
logged 133 main-isolate stalls over ~10 h (24 s blocked, worst 1.6 s), mostly
on idle Home and ~20x more often right after sync phases and uploads. Every
index save copied, keyed and fingerprinted every record on the main isolate
and copied the full List<Wal> into an encoding isolate; sync screens rescanned
the inventory on every notify; reconcile polled ~2/s after a reconnect.

- Saves: Wal persisted-field setters mark dirty identities; a long-lived index
  worker owns the serialized rows and receives only changed JSON maps and
  removed tokens. Durable is acknowledged only after flush + atomic rename;
  failed deltas are retained and retried. No whole-index fingerprint.
- Load: decode and Wal construction run off-isolate; the worker seeds
  unchanged rows from disk, so the first save sends zero unchanged records.
- Format: unchanged version-1 wals.json, backup and quarantine recovery;
  retired/foreign/synced records and upload-order tie-breaks preserved.
- Views: SyncProvider derives pending/uploaded/attention/refusal lists and
  per-day totals incrementally (WalDerivedViews); Home, On the Way and Device
  Settings read them. Integration and widget fakes derive the same views from
  their raw inventory (WalDerivedSyncViews).
- Reconcile: visits uploaded rows only, joins an active pass, spaces passes by
  20 s; job backoff, fairness and acknowledgement unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…irst frame

The newest-anchored layout needed extra frames for its anchor correction, so a
short live transcript (even one segment) was blank on its first frame;
capturing_empty_state_test failed 20 of 23. The viewport now measures its anchor
and initial latest position during layout, before paint. Short transcripts show
immediately; a 1,000-segment open still builds about one screen of rows. The
extra pumps added to episodes_ui_test are removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…bove grow

Review finding (GLM): on a short scrollable live transcript, a photo group or
an older row growing during a drag or fling changed the newest-anchored
viewport's anchor with pixels unchanged, moving every visible row by the
inserted height under the reader's finger, and the correction bailed for the
whole gesture. The viewport now compensates the leading-edge shift with
offset.correctBy in the same layout pass. Regression tests cover short and
long histories, photo insertion/growth and older-row growth across drag, fling
and idle; first-frame rendering and 1,000-segment laziness still hold.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ecover in-session

Review findings (GLM) on the delta index worker:
- A dead worker isolate (OOM/VM kill) left apply() awaiting forever, wedging
  every later save and the capture flush queue. Exit/error listeners now fail
  pending requests and release the queue; the replacement worker is seeded from
  a full snapshot of the in-memory index, preserving tokens, admitted deltas
  and every custody bucket.
- After loading from the backup because wals.json was corrupt and could not be
  quarantined, the worker seeded from the corrupt main file and every save
  failed for the session. Workers now receive the exact source the loader
  validated; a failed startup retries from memory.
- The load-time invalid-entry repair used the legacy whole-file writer on the
  same wals.json(.tmp) as the live worker with no shared lock. Loading,
  quarantine/repair, worker seeding and writes now share one lock.

Every failure fails closed: no durable acknowledgement before flush + rename.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level Git-on-my-level changed the title test(mobile-perf): live preview, live episode, Device Settings/On the Way windows + two device-run fixes perf(mobile): WAL index scales with changes, live transcript/Tasks first build, device perf harness Oct 28, 2026
Git-on-my-level and others added 8 commits October 28, 2026 18:27
…tion sweep

Dated syncedAt stamps were older than the synced-copy retention cutoff, so the
startup sweep removed all seeded synced records and Home saw only the pending
backlog. Legacy syncedAt 0 is never auto-removed, matching a long-lived phone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o a part file

Keeps transcript.dart under its line-count ratchet (1590) after the
newest-anchored viewport landed; no behavior change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Attribution-only runs (never baselines) enable debugProfileBuildsEnabled so a
slow first build, such as the first Tasks switch, names its widget in the trace.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… rows

Device regression (iPhone 15 Pro Max, 3 runs before/after): opening a saved
conversation's transcript and flinging it went from 0/101/100 ms of main-isolate
stalls per run to 223/257/116 ms. The trace put ~15% of samples in
_TranscriptPlaybackScrolling._reportTopVisibleSegment, which walked the sliver
tree on every scroll notification. Sliver discovery is now cached, each sliver
needs one reveal calculation, and remaining row positions use existing layout
offsets; first-frame layouts and reveal calls per frame are unchanged from 120
to 1,200 rows (test).

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflict in live_preview_coverage.dart: keep main's settled-tail and
untimed-grace semantics, prepared once per final snapshot so the live
transcript view can reuse it across preview revisions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PostHog mobile-wal-delta-index-off (ops_kill, default false). True makes
the next launch save every index change through the pre-delta
full-snapshot writer; both writers produce the same version-1 file, so
flipping either way needs no migration. Read once per process with a 1 s
bound; offline or failed reads keep the delta writer on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level marked this pull request as ready for review October 28, 2026 16:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T16:23:46.756269Z de3e78a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Git-on-my-level
Git-on-my-level merged commit fab07e2 into main Oct 28, 2026
63 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/iphone-perf branch October 28, 2026 17:02
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