Repository navigation
perf(harness): on-device lag capture - #23413
Conversation
The host interaction harness could not see the lag David feels: host flutter test cannot raster, its timings swung 5-10x between runs, and it ran with semantics on, unlike production. Routine render telemetry was removed from PostHog on 2026-10-17, so the device signal stays local. - LagRecorder (lib/utils/analytics/lag_recorder.dart), fed by the existing MobilePerformanceTelemetry frame-timings callback while Settings -> Developer -> Debug logs is on: per surface (routeToPage page type or Home tab) frame counts over 16.7/33.3/100 ms, build- vs raster-bound, slow frames while scrolling / after a tap / idle; worst frames with wall-clock time; tap-to-frame latency including the tap handler's sync work; and UI-isolate stalls from a 250 ms watchdog that runs only while capture is on. Writes mobile_lag_* events to the local debug log; a report on every background and every ~18k frames. - app/tool/lag_report.py turns a shared debug log into a ranked table. - Integration perf scenarios run with semantics off (PERF_SEMANTICS=1 to opt back in) and report a per-phase UI split from FlutterTimeline. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d6cd20f07e
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| _lagActive = _attached && _foreground && diagnosticsEnabled?.call() == true; | ||
| if (_lagActive) { | ||
| recorder.startWatchdog(); | ||
| } else { | ||
| recorder.stopWatchdog(); | ||
| } |
There was a problem hiding this comment.
Gate all recorder state on the debug-log switch
When debug logging is disabled, this branch only stops the watchdog; LagInputScope still forwards every pointer and scroll event to the recorder, and pending frame/tap/stall aggregates are never cleared. Consequently, after a user disables and later re-enables debug logs without restarting, the next mobile_lag_report can include taps or measurements collected before the current capture session, corrupting the report and adding always-on input instrumentation. Pause input collection and reset or flush recorder state when _lagActive becomes false.
Useful? React with 👍 / 👎.
| String lagSurfaceFor(Route<dynamic> route, {required int homeTab}) { | ||
| final label = lagRouteLabels[route]; | ||
| if (label != null) return label; | ||
| if (route.isFirst) return homeTab == 0 ? 'home_tab:conversations' : 'home_tab:tasks'; |
There was a problem hiding this comment.
Derive the first route's surface from the displayed shell
For signed-out, onboarding, consent, and permissions states, the first navigator route still renders AppShell, but this branch unconditionally labels it home_tab:conversations. With debug logging enabled during those flows, their frames and stalls are therefore merged into the Home conversations bucket, defeating the screen attribution this recorder is intended to provide; the root label needs to follow the shell's actual displayed state rather than Route.isFirst alone.
Useful? React with 👍 / 👎.
| _keepWorst(_worstStalls, record, 'blocked_ms'); | ||
| _emit('mobile_lag_stall', record); |
There was a problem hiding this comment.
Rate-limit individual stall log events
On a device experiencing sustained UI-isolate delays—the primary situation this recorder targets—the 250 ms watchdog can call this path several times per second, and every call queues a separate file append. Unlike severe-frame events, stalls have no rolling rate limit even though the report already preserves bounded worst-stall samples and aggregate counts, so prolonged lag can generate thousands of writes, perturb the performance being measured, and rotate away useful debug-log history.
Useful? React with 👍 / 👎.
| if (worst <= severeUs) return; | ||
|
|
||
| final record = <String, Object?>{ | ||
| 'at': _wallClock().toIso8601String(), |
There was a problem hiding this comment.
Timestamp slow frames at their actual vsync time
When addTimingsCallback delivers its usual batch of frame timings, this assigns every slow frame the wall-clock time at which the batch is processed rather than the time represented by vsyncStartUs. Since the code already accounts for batches arriving up to a second late, the reported at values cannot be reliably correlated with user actions or neighboring debug events, and multiple frames may receive the same clock value and be collapsed by lag_report.py's (at, surface) key. Convert the monotonic vsync timestamp to wall time instead of calling the current wall clock here.
Useful? React with 👍 / 👎.
Git-on-my-level
left a comment
There was a problem hiding this comment.
SHIP — Sol/P88 review of current head d6cd20f. No P0/P1 findings. Reviewed recorder bounds, local-only DebugLogManager emission, main.dart input/navigation wiring, timing/watchdog lifecycle, report parser, production-semantics host changes and targeted test source. Source review only: I did not rerun Flutter tests or measure device overhead; existing CI and physical/TestFlight acceptance remain separate gates. No merge requested or performed.
…capture is off #23419 (production-shell perf gate) carries the same host-harness changes this PR made (semantics off, per-phase split) and more, in the same four integration_test/perf files, so drop them here to avoid a conflict. The device-capture how-to moves to app/docs/performance.md. LagInputScope's callbacks now return at once unless Debug logs capture is on, and turning capture off forgets an in-flight gesture. The global listener is annotated for #23415's global-input-listener ratchet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#23419's production-shell gate fingerprints all of main.dart and copies its telemetry field and builder chain into a generated shell, so new root wrappers in main.dart (LagInputScope, _LagHomeTabListener) would make the shell stale and could not compile there. Take main.dart back to main. - MobilePerformanceTelemetry builds its own LagRecorder and writes through the emit main.dart already passes; each lag event names itself in an 'event' field (lag_report.py reads both shapes). - Pointers come from GestureBinding's global pointer route: no widget, and it runs before the arena sweep that fires onTap. A drag past touch slop is a scroll, with an 800 ms tail after lift for the fling; one tracked pointer at a time. - The Home tab comes from a one-line hook in HomeProvider.setIndex. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e5e574585
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| final watch = Stopwatch()..start(); | ||
| WidgetsBinding.instance.addPostFrameCallback((_) { |
There was a problem hiding this comment.
Start tap timing before gesture recognizers process pointer-up
When a tap recognizer has already won its gesture arena before pointer-up, its synchronous onTap handler runs before this stopwatch starts: Flutter's PointerRouter implementation dispatches per-pointer routes before global routes, and the tap recognizer processes pointer-up immediately. Consequently, an expensive tap handler can block the UI for hundreds of milliseconds yet produce a fast tap_to_frame_ms, omitting precisely the synchronous work this metric claims to include. Capture the start time before recognizer dispatch rather than starting the stopwatch in the global pointer-up callback.
Useful? React with 👍 / 👎.
| if (!value && _lagActive) lag.writeReport('background'); | ||
| _foreground = value; | ||
| _generation++; | ||
| _epoch = identityEpoch(); | ||
| _refreshLag(); |
There was a problem hiding this comment.
Include delayed frame batches in the background capture
In release/TestFlight builds, backgrounding immediately after a lag can omit the frames the user intended to capture. Flutter batches frame timings approximately once per second in release mode, but this writes and clears the report immediately, then disables capture; any outstanding foreground-frame batch delivered afterward is discarded by _timings's if (!_foreground) return. This particularly affects the documented workflow of backgrounding after reproducing a lag. Preserve the closing capture until outstanding timings have been processed, attributing late batches by their frame timestamps, and write a final report containing them.
Useful? React with 👍 / 👎.
perf(harness): on-device lag capture
What changed and why
David reports that the iOS app (TestFlight 1.0.573) "still lags quite a lot sometimes when I'm scrolling or clicking on things". The interaction harness didn't reproduce it, for three reasons:
flutter testcan't see what a phone does. It can't raster, doesn't run AOT code, and its timings swung 5–10× between runs in the previous round (perf(episodes): keep the live-episode surfaces O(1) per capture notify #23278).testWidgetsturns semantics on by default. Production iOS ran with semantics forced on by the rage-click tracker; that is fixed separately in the app-wide fixes PR. After that fix, production runs with semantics off. Either way, the host arm never matched the device.Mobile Render Observationwas removed from PostHog on 2026-10-17 (FinOps, ingestion drop at 0%). The client telemetry collector isn't deployed, and its flags must stay off.This PR makes lag measurable where it's felt, without sending anything off the device:
LagRecorder(app/lib/utils/analytics/lag_recorder.dart)MobilePerformanceTelemetry, and runs only while Settings → Developer → Debug logs is on. In release and TestFlight builds it records:routeToPagepushes, or the Home tab): frames, slow (>16.7 ms on either thread), severe (>33.3 ms) and freeze (>100 ms) counts, build-bound versus raster-bound, and whether the user was scrolling, had just tapped or was idle;main.dart, so test(perf): gate mobile scenarios through production app wrappers #23419's production-shell fingerprint stays valid:emitthatmain.dartalready passes; each lag event names itself in aneventfield.GestureBinding's global pointer route, not a widget. That route runs before the gesture-arena sweep that firesonTap, so tap timing includes the handler. A drag past touch slop counts as a scroll, with an 800 ms tail after lift for the fling; one pointer is tracked at a time.HomeProvider.setIndex.app/tool/lag_report.pyturns a shared debug log into a ranked table of surfaces, worst frames, slow taps and stalls.integration_test/perf/. The device-capture how-to lives inapp/docs/performance.md.How David captures a lag
mobile_lag_report.python3 app/tool/lag_report.py omi_debug_YYYYMMDD.log.The report tells us which screen lagged, whether the GPU (raster) or the UI isolate (build) was the bottleneck, and whether it happened while scrolling, after a tap or idle. That decides which kind of fix applies.
Privacy
page.EMISSION.mdrecords this.How it was verified
test/unit/lag_recorder_test.dart(11 tests) covers:testerdrags reaching the recorder through the global pointer route, with no widget mounted, and the Home-tab hook clearing on dispose.mobile_performance_telemetry_test.dart(5 tests) still passes.flutter analyzeis clean onlib/utils/analytics.lag_recorder_test.dart, 8 tests).check_mobile_ui_isolate.pyand ci(app): add scoped mobile performance ratchets #23415's stricter version, with no allow annotations, because there's no root listener widget.main.dartis byte-identical tomain, so test(perf): gate mobile scenarios through production app wrappers #23419'sperf_shell.py --checkis unaffected.check_mobile_ui_isolate.py) passes.app/tool/lag_report.pywas checked against a synthetic log.UI-Evidence: none -- no visual change; adds input listeners, a recorder and debug-log events only.
Product invariants affected
INV-PERF-1: the recorder runs on every frame-timings batch and stays O(frames) with no allocation unless a frame is severe; the watchdog timer runs only while the user has debug logs on. This adds the device-side measurement the invariant has lacked.
INV-DATA-1: unaffected; no routing or production data path changes (selected by touching
main.dart).Failure-Class: none
🤖 Generated with Claude Code