Skip to content

perf(app): stop holding semantics on for rage-click context on iOS - #23400

Merged
Git-on-my-level merged 1 commit into
mainfrom
perf/ios-semantics-off
Oct 23, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
perf/ios-semantics-off

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Problem

On every production iOS build with a PostHog key, RageClickContextTracker (mounted app-wide in main.dart) called SemanticsBinding.instance.ensureSemantics() at startup and held it for the app's lifetime. So every frame also compiled the semantics (accessibility) tree, even with VoiceOver off. David reports scroll and tap lag on iPhone that our harnesses never reproduced, because:

  • host harnesses never mount the tracker;
  • testWidgets turns semantics on by default in both arms.

Measurement

app/test/perf/rage_click_semantics_cost_test.dart scrolls a 400-row list for 240 drags with semantics off versus held on. The SEMANTICS phase is 17–25% of UI-thread pipeline time with semantics on (runs: 24.7%, 19.3%, 16.9%; re-run here: 19.6%, 16.6%), against 0 ms off.

Change

The tracker no longer holds a SemanticsHandle. On each pointer down it does one hit test and reads the semantics annotations already present on the render objects under the pointer:

  • the route title comes from namesRoute;
  • the control label comes from identifiers, explicit labels, buttons/links and tooltips.

A plain tap target still reports tap_target, never its content. PostHog rage clicks keep their screen and control context.

Tests

  • test/widgets/rage_click_context_tracker_test.dart: the existing context tests, plus a guard that the tracker leaves semantics off.
  • test/perf/rage_click_semantics_cost_test.dart: the cost probe.
  • 5 tests pass locally. flutter analyze is clean.

UI-Evidence: none -- no visual change.

Release

This goes into iOS 1.0.574, to replace 1.0.573 in App Store review, per David's 10-23 approval if the cost was confirmed. Measured by the perf hill-climb lane (Opus); the same commit also sits on lane/perf-hillclimb.

Product invariants affected

INV-PERF-1: per-frame work must not scale with app-wide state when nothing relevant changed. This removes an app-lifetime per-frame semantics compile on iOS.

Failure-Class: none

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

RageClickContextTracker held SemanticsBinding.ensureSemantics() for the
app's lifetime on iOS builds with PostHog, so every production iOS frame
also compiled the semantics tree: 17-25% of UI-thread pipeline time while
scrolling a row-heavy list (test/perf/rage_click_semantics_cost_test.dart).
Host harnesses never mounted the tracker, so they never saw it.

Resolve the tapped control and route title from the render objects under
the pointer instead (one hit test per pointer down). Labels still come only
from identifiers, explicit labels, buttons/links and tooltips; a plain tap
target reports tap_target, never its content.

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-23T13:40:43.097936Z fbae11c PR opened
ℹ️ 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: fbae11ce73

ℹ️ 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 +74 to +75
if (node is SemanticsAnnotationsMixin && node.properties.namesRoute == true) {
found = _normalize(node.properties.label ?? '') ?? _textBelow(node);

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 route names on the platform that mounts the tracker

On iOS, where this tracker is mounted, Flutter 3.44.5's AppBar sets namesRoute to null; it is true only on Android, Fuchsia, Linux, and Windows. Consequently this condition never recognizes a normal iOS app-bar title, so screenName is null and setInteractionContext leaves the previous screen super-property in place. The new test passes only because it uses the host's default platform despite describing production iOS; exercise it with TargetPlatform.iOS and use the iOS header/title annotation as a fallback.

Useful? React with 👍 / 👎.

Comment on lines +92 to +100
for (final node in path) {
if (node is! SemanticsAnnotationsMixin) continue;
final p = node.properties;
final identifier = _normalize(p.identifier ?? '');
if (identifier != null) return identifier;

if (!node.rect.contains(localPosition) || node.flagsCollection.isHidden) return null;
final interactive = p.button == true || p.link == true || p.textField == true || p.onTap != null;
final label = _normalize(p.label ?? '');
if (label != null && interactive) return label;

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 Honor replacement semantics before inspecting descendants

When an outer Semantics(excludeSemantics: true, ...) intentionally replaces its child's semantics, this deepest-first scan can return an inner control before reaching that replacement annotation. For example, OmiDateFilterChip replaces its child OmiButton with the label Remove filter, …, but the inner TextButton is encountered first and _textBelow reports the visual … × label instead. Respect SemanticsAnnotationsMixin.excludeSemantics by discarding deeper candidates at that boundary so rage-click targets match the effective semantics tree.

Useful? React with 👍 / 👎.

Comment on lines +111 to +121
for (final node in path) {
if (node is SemanticsAnnotationsMixin) {
final p = node.properties;
if (p.button == true) return 'button';
if (p.link == true) return 'link';
if (p.textField == true) return 'text_field';
if (p.slider == true) return 'slider';
if (p.onTap != null) return 'tap_target';
}
if (node is RenderSemanticsGestureHandler && node.onTap != null) return 'tap_target';
if (node is RenderEditable) return 'text_field';

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 Read semantics from custom control render objects

Controls that implement semantics directly in describeSemanticsConfiguration are invisible to these type checks. Flutter's material Slider, used in the goals, device-control, and notification-settings screens, is handled by its own render object rather than SemanticsAnnotationsMixin or RenderSemanticsGestureHandler; therefore tapping or dragging any of those sliders now records unlabeled_surface, whereas the previous semantics-tree implementation returned the slider fallback. Inspect each hit render object's semantics configuration, or otherwise recognize these direct-semantics controls.

Useful? React with 👍 / 👎.

@kodjima33

Copy link
Copy Markdown
Collaborator

@Git-on-my-level heads up from Nik: iOS 1.0.574 (build 1458) is in App Store review and has everything (onboarding, stay offer, your lag fix). Please do not withdraw or replace it. Three withdrawals last night each restarted Apple's queue, which is why nothing shipped. A guard now resubmits 1.0.574 if it gets pulled, and #23444 makes the promote script refuse while a version is in review. Newer builds wait for the next train after 1.0.574 is released.

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.

2 participants