Skip to content

perf(core): avoid unconditional per-view accessibility bridge calls on view mount #11696

Backlog

Description

@herefishyfish

Problem

ViewCommon.onLoaded() unconditionally runs setupAccessibleView(this) on every mounted view, crossing the native bridge on every view even when no accessibility service is active and the view has no accessibility properties:

  • Android: updateAccessibilityProperties queues a microtask that makes 3 Java calls per view (getAccessibilityDelegate(), setAccessibilityDelegate(TNSAccessibilityDelegate), and setContentDescription(null) on non-TextView views). On large view trees (~1,000+ views), this post-attach microtask adds ~70 ms of main-thread work before the first frame paints. In addition, application.android.ts registers two colliding pairs of AccessibilityManager listeners (leaking one on exit), returns undefined on the first isAccessibilityServiceEnabled() call, and eagerly resolves 12 Android widget classes in RoleTypeMap.
  • iOS: setupAccessibleView writes uiView.tag = view._domId on every mounted view solely so UIAccessibilityElementFocusedNotification can look up the View via getViewByDomId.

Proposed Solution

  • Android: Monitor AccessibilityManager once with three levels (None, Enabled, TouchExploration):
    • Skip per-view mount setup while no accessibility service is enabled, and backfill loaded views across windows and modals when a service or touch exploration turns on.
    • Under Enabled without touch exploration (e.g. password managers, Switch Access, Appium/UiAutomator), attach TNSAccessibilityDelegate only to views with accessible, accessibilityRole, accessibilityIdentifier, or testID, and track delegate attachment in JS instead of calling getAccessibilityDelegate().
    • Skip redundant setContentDescription(null) and instanceof checks in applyContentDescription when a view has no content-description inputs, while keeping explicit accessibilityLabel/Value/Hint updates immediate (preserving Espresso behavior).
    • Cache AccessibilityManager, lazily resolve RoleTypeMap class names, and short-circuit TextBase default descriptions.
  • iOS: Stop writing uiView.tag = view._domId at mount, and resolve focused views in UIAccessibilityElementFocusedNotification by matching nativeViewProtected across all windows and modals.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions