Skip to content

ci(app): add scoped mobile performance ratchets - #23415

Merged
Git-on-my-level merged 4 commits into
mainfrom
lane/perf-gate-static
Oct 24, 2026
Merged

Git-on-my-level merged 4 commits into
mainfrom
lane/perf-gate-static

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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.py instead 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-semantics is 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.
  • Other new rules use the existing per-file, per-rule merge-base no-increase baseline. They recognize root/arbitrary-child Listener/scroll NotificationListener wrappers, Capture/Sync/Conversation/Message/Episode/Device/VoiceRecorder addListener subscriptions without a selected-key early return, build/builder JSON decode and sorts, and list-item Opacity/saveLayer scopes, including same-file row/painter construction. Input callbacks are counted individually, so a new move callback cannot hide inside an existing wrapper count. Existing hits may stay level or shrink; new files start at zero.
  • Lexical masking handles nested block comments, raw/triple strings and executable interpolation. Same-file helper/tear-off resolution and deferred event-handler exclusion avoid broad file bans. Remediation stays beside each diagnostic; measured, bounded cases retain local reasoned exceptions except forced semantics.

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.
  • Review regressions: selector guards compare the selected and stored key in the same equality; named listeners/helpers stay within their owning class; positional SliverChildBuilderDelegate rows, Overscroll/UserScroll notifications and arbitrary forwarded Widget field names participate. All six review cases were reproduced before fixing, with negative fixtures retained.
  • Source inventory: no forced-semantics calls; existing scoped hits in 26 files are measured from merge-base sources rather than committed exemptions. The real 26-file baseline run passed.
  • scripts/pr-preflight --suggest, nice -n 10 scripts/pr-preflight --pr-body-file … and OMI_PR_BODY_FILE=… nice -n 10 make preflight: passed; both manifest lanes ran all 15 selected checks on the final source.
  • No local Flutter jobs, physical-device access, GCP tier or production access used; no phone frame-time improvement is claimed.

UI-Evidence: none -- static tooling and documentation only; no rendered UI change.

🤖 Generated with Claude Code

Git-on-my-level and others added 3 commits October 23, 2026 21:50
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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-23T15:52:35.647834Z 2ce0735 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +570 to +571
if _guarded_before(body, work.start() if work else len(body), {receiver_name}):
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +457 to +460
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, "(", ")")))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +514 to +516
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +561 to +563
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +475 to +480
while True:
added = {
(a, b)
for name, a, b in declarations
if referenced(rf"\b{re.escape(name)}\b")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +511 to +513
# 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 []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +487 to +489
if kind == "build":
spans = [(a, b) for name, a, b in declarations if name == "build"]
spans += _callback_spans(masked, r"builder|itemBuilder|separatorBuilder")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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]):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +491 to +494
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, "(", ")")))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +404 to +407
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
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +147 to +150
"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),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +592 to +595
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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Git-on-my-level added a commit that referenced this pull request Oct 24, 2026
…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]>
Git-on-my-level added a commit that referenced this pull request Oct 24, 2026
* 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]>
@Git-on-my-level
Git-on-my-level merged commit c129e7c into main Oct 24, 2026
49 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/perf-gate-static branch October 24, 2026 10:50
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