Repository navigation
ci(app): add scoped mobile performance ratchets - #23415
Conversation
Reuse the UI-isolate checker for semantics ownership, root input observation, high-frequency provider subscriptions, build-time JSON/sorts, and list-item layer costs. Preserve merge-base debt and add mutation/negative fixtures. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Retain the optional performance guidance patch as a local handoff artifact. The app changelog gate requires a fragment outside this lane ownership for documentation-only app changes; diagnostics and the PR body carry remediation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adding a high-frequency callback to an existing root wrapper now increases its ratchet count. Callback-local exceptions do not exempt future callbacks. Resolve same-file row painters and avoid repeated full-tree lexing for each provider hook. 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: ee8818b57d
ℹ️ 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".
| if _guarded_before(body, work.start() if work else len(body), {receiver_name}): | ||
| return False |
There was a problem hiding this comment.
Verify the guard compares the selected key
When a provider callback contains any equality involving an assigned field and separately references the provider-derived value, _guarded_before treats it as an unchanged-key guard even if the two values are never compared. For example, final next = capture.version; if (next > 0 && _version == 0) return; _version = next; makes this rule report zero hits, although nearly every notification still performs the work, allowing a new unselected high-frequency subscription through the ratchet.
Useful? React with 👍 / 👎.
| spans = _callback_spans(masked, r"itemBuilder|separatorBuilder") | ||
| # Eager lists and slivers have children rather than itemBuilder. | ||
| for match in re.finditer(r"\b(?:ListView|SliverList|SliverChildListDelegate)\s*\(", masked): | ||
| spans.append((match.end(), _matching(masked, match.end() - 1, "(", ")"))) |
There was a problem hiding this comment.
Include SliverChildBuilderDelegate row builders
When rows are supplied through a positional SliverChildBuilderDelegate callback, that callback is absent from the list scopes because only named itemBuilder/separatorBuilder callbacks and eager list constructors are collected. This is a live construction style in files such as app/lib/pages/conversations/conversations_page.dart:537, so adding Opacity or saveLayer inside one of those row builders produces no list-item-layer hit and bypasses the new ratchet.
Useful? React with 👍 / 👎.
| if masked[match.start() : match.end()].startswith("NotificationListener"): | ||
| if "<" in match.group() and not re.search(r"\b(?:Scroll\w*Notification|Notification|dynamic)\b", match.group()): | ||
| return [] # domain events are not per-scroll/frame observation |
There was a problem hiding this comment.
Recognize all scroll notification subclasses
For typed notification listeners, this filter only accepts types beginning with Scroll, so NotificationListener<OverscrollNotification>(onNotification: expensive, child: child) is classified as a domain event and reports no hit. OverscrollNotification is a scrolling notification that can fire repeatedly during user input, so this common subtype can introduce exactly the app-wide observation work the rule is intended to prevent.
Useful? React with 👍 / 👎.
| callback = re.match(r"\s*(?:this\.)?(\w+)\b", masked[start:]) | ||
| if callback: | ||
| span = next(((a, b) for name, a, b in _declarations(masked) if name == callback.group(1)), None) |
There was a problem hiding this comment.
Resolve named listeners within their owning class
When multiple classes in one Dart file declare the same callback name, this next(...) selects the first declaration in the file rather than the declaration belonging to the listener's class. A guarded onCapture in an earlier class therefore causes an unguarded capture.addListener(onCapture) in a later class to report zero hits, letting the new high-frequency subscription bypass the ratchet.
Useful? React with 👍 / 👎.
| while True: | ||
| added = { | ||
| (a, b) | ||
| for name, a, b in declarations | ||
| if referenced(rf"\b{re.escape(name)}\b") | ||
| } |
There was a problem hiding this comment.
Keep helper traversal within the declaring class
When a selected build or row scope references a helper name, this comprehension adds every same-named declaration in the file, including methods on unrelated classes. In a valid multi-widget file where one class's build calls helper() and another class has a data-loading helper() containing jsonDecode or sort, the latter is incorrectly classified as build work, so an otherwise valid change is blocked by a false ratchet increase.
Useful? React with 👍 / 👎.
| # Root entry points or arbitrary-child wrappers, not a local gesture surface. | ||
| if path != MAIN_DART and not re.match(r"(?:widget\.child\b|child\b|MaterialApp\s*\(|Navigator\s*\(|Router\s*\()", named.get("child", ("", 0))[0]): | ||
| return [] |
There was a problem hiding this comment.
Track forwarded children regardless of field name
When a reusable app-wide wrapper names its forwarded widget anything other than exactly child or widget.child, this check classifies the listener as local and returns no hit. For example, a widget with final Widget content and Listener(onPointerMove: walkTree, child: content) still observes the caller's arbitrary subtree but bypasses the global-input-listener ratchet solely because the field was named content.
Useful? React with 👍 / 👎.
Bind unchanged guards to the compared key, resolve helpers within their class, and include positional sliver rows and all scroll notification subclasses. 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: 2ce0735a7b
ℹ️ 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".
| if kind == "build": | ||
| spans = [(a, b) for name, a, b in declarations if name == "build"] | ||
| spans += _callback_spans(masked, r"builder|itemBuilder|separatorBuilder") |
There was a problem hiding this comment.
Exclude local callback declarations from build scopes
When a build/builder body declares a local event handler, the handler's body is lexically inside the selected span, so deferred work such as void handleTap() { jsonDecode(raw); } is counted as json-in-build even though it runs only after the tap. This can block valid changes under the no-increase ratchet; nested function bodies should be excluded unless the function is invoked synchronously from the selected scope.
Useful? React with 👍 / 👎.
| added = set() | ||
| declared_names = {name for name, _, _ in declarations} | ||
| for start, end in selected: | ||
| for ref in re.finditer(r"\b[A-Za-z_]\w*\b", masked[start:end]): |
There was a problem hiding this comment.
Ignore named-argument labels during helper traversal
When a deferred class method has the same name as its callback parameter, as in Button(onPressed: onPressed), this identifier scan treats the onPressed: label itself as a helper reference because only the value lies in _deferred_spans. It therefore traverses the event handler and reports its JSON decoding or sorting as build-time work, despite the handler not executing during build; helper traversal should ignore identifiers followed by :.
Useful? React with 👍 / 👎.
| spans = _callback_spans(masked, r"itemBuilder|separatorBuilder") | ||
| # Eager lists and slivers have children rather than itemBuilder. | ||
| for match in re.finditer(r"\b(?:ListView|SliverList|SliverChildListDelegate)\s*\(", masked): | ||
| spans.append((match.end(), _matching(masked, match.end() - 1, "(", ")"))) |
There was a problem hiding this comment.
Trace builders passed to custom sliver delegates
Although direct SliverChildBuilderDelegate callbacks are now handled, the live ListView.custom plus _StableChatMessageDelegate(builder: ...) construction in app/lib/pages/chat/page.dart:363-368 remains outside every list scope: ListView.custom does not match the eager-constructor regex, and the delegate subclass's named builder is not collected here. Adding Opacity or saveLayer to that row callback therefore still produces zero list-item-layer hits and bypasses the ratchet.
Useful? React with 👍 / 👎.
| pattern = re.compile( | ||
| r"^[ \t]*(?:(?:static|Future|Widget|void|bool|int|double|String|List|Map|Set|[A-Z]\w*)" | ||
| r"[\w<>?, .\[\]]*\s+)(\w+)\s*\(", re.M | ||
| ) |
There was a problem hiding this comment.
Follow getters read from build scopes
When build reads a same-class getter, such as Map get parsed => jsonDecode(raw) followed by Text(parsed.toString()), the getter is absent from _declarations because both declaration patterns require a method parameter list. Its body is therefore never selected, and the synchronous decode reports zero json-in-build hits; sorting in a getter is missed the same way. Getter bodies referenced by a selected build scope need the same traversal as ordinary helpers.
Useful? React with 👍 / 👎.
| "json-in-build", | ||
| re.compile(r"\b(?:jsonDecode|json\s*\.\s*decode)\s*\("), | ||
| "decode before build in the data layer; use offUiIsolate for history-sized payloads", | ||
| accept=lambda text, match: _in_ui_scope(text, match.start(), "build") and _outside_off_ui_isolate(text, match), |
There was a problem hiding this comment.
Recognize JsonDecoder and JsonCodec calls in builds
When build decodes with Dart's equivalent codec APIs, for example const JsonDecoder().convert(raw) or const JsonCodec().decode(raw), this pattern reports zero json-in-build hits because it only recognizes the jsonDecode and json.decode shorthands. These calls perform the same synchronous parsing on the UI isolate, so new build-time decoding can bypass the ratchet solely by using the standard codec classes.
Useful? React with 👍 / 👎.
| names = set(re.findall(rf"\b{HIGH_FREQUENCY_PROVIDER}\??\s+(\w+)", masked)) | ||
| for binding in re.finditer(r"\b(\w+)\s*=\s*([^;\n]+)", masked): | ||
| if re.search(rf"\b{HIGH_FREQUENCY_PROVIDER}\b", binding.group(2)): | ||
| names.add(binding.group(1)) |
There was a problem hiding this comment.
Resolve provider receiver types within their lexical scope
When one class declares CaptureProvider controller and another class in the same file declares AnimationController controller, the file-wide names set causes the animation controller's controller.addListener(tick) to be reported as an unselected provider subscription. This contradicts the rule's explicit AnimationController exemption and can block benign listeners in multi-class files; receiver-name inference must respect the owning class and local shadowing.
Useful? React with 👍 / 👎.
…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]>
* perf(harness): on-device lag capture and production-condition host runs 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]> * perf(harness): leave the host harness to #23419; gate lag input when 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]> * perf(harness): capture lag input without touching main.dart #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]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Problem and change
The existing UI-isolate ratchet did not cover app-wide input observation, raw high-frequency provider subscriptions, build-time JSON/sorts, list-item layers, or forced semantics. Extend
.github/scripts/check_mobile_ui_isolate.pyinstead of adding a parallel checker or workflow. The same manifest entries run the checker and its tests in both local and CI lanes, including when the checker itself changes. Optional app/docs guidance is retained as a local patch for the parent; the committed change stays within the three tooling files.forced-semanticsis absolute over handwritten app/lib sources, including unchanged/existing files. Its explicit call-specific allowlist is empty; merge-base debt and inline exceptions cannot hide a new call.This is bounded lexical analysis, not a Dart type checker: cross-file dispatch, arbitrary aliases and collection cardinality require review/runtime measurement. Scope/negative fixtures cover local gestures, domain events, leaf listenables, selectors/selected callbacks, data-layer parsing, event handlers and opacity outside lists. Build-time sorts are candidates regardless of inferred size; a bounded sort needs a local measured reason.
Incident evidence and shared primitive
#23400 removed the app-lifetime semantics handle in the iOS rage-click wrapper, which enabled semantics compilation even with VoiceOver off. The absolute rule rejects that call shape in an old or new file. #21517 supplies the existing shared ratchet for history work/notify amplification; this PR extends that primitive and its masking/scope support.
#21323, #23018 and #23278 provide harness, rebuild/paint isolation and per-notify derivation context. They do not establish that every lexical pattern here caused their regressions. In particular #23018 was not a fast-timer defect; sort/list-layer fixtures are preventive controls, not new causal findings.
Product invariants affected
INV-PERF-1: strengthen the existing UI-isolate guard while keeping baseline debt visible and limiting exceptions to an individual justified occurrence. No shipped Dart, protected telemetry/language files, firmware or workflows change.
Failure-Class: none
Validation
nice -n 10 python3 .github/scripts/test_check_mobile_ui_isolate.py: 66 tests passed, with mutation fixtures for every added rule, new/existing-file growth, unchanged/decreased debt, comments/strings, scope negatives, selected-listener guard ordering and absolute semantics checks.scripts/pr-preflight --suggest,nice -n 10 scripts/pr-preflight --pr-body-file …andOMI_PR_BODY_FILE=… nice -n 10 make preflight: passed; both manifest lanes ran all 15 selected checks on the final source.UI-Evidence: none -- static tooling and documentation only; no rendered UI change.
🤖 Generated with Claude Code