Skip to content

Only generate recursive accessibility label for accessible elements #51988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

janicduplessis
Copy link
Contributor

@janicduplessis janicduplessis commented Jun 12, 2025

Summary:

When trying to implement e2e tests using maestro in a large app I ran into major performance issues. I tracked it down to the generation of recursive accessibility labels.

The maestro iOS driver uses XCUIElement snapshot dictionaryRepresentation here to get a representation of the view hierarchy. The problem is that will query the accessibilityLabel for every single view, starting from the root of the app. It goes without saying that this is extremely slow since it traverses the view hierarchy, executing a recursive function on each one.

I think the only way to fix this is to avoid generating these recursive labels when not needed. From my understanding these should only be needed for accessible views.

Changelog:

[IOS] [CHANGED] - Only generate recursive accessibility label for accessible elements

Test Plan:

  • Tested using VoiceOver in RN tester to make sure it works exactly the same.
  • Tested in an app using Maestro to make sure this fixes the performance issue.
  • Tested in RNTester running Maestro e2e test by creating a larger view hierarchy to make the problem more apparent, and simulate a real app. Using this code in RNTesterAppShared.js

Before:

❯ yarn e2e-test-ios
yarn run v1.22.22
$ ./scripts/maestro-test-ios.sh

Waiting for flows to complete...
[Passed] flatlist (14s)
[Passed] text (28s)
[Passed] modal (16s)
[Passed] image (8s)
[Passed] button (10s)
[Passed] legacy-native-module (32s)
[Passed] pressable (32s)
[Passed] new-arch-examples (35s)

8/8 Flows Passed in 2m 55s

✨  Done in 180.26s.

After:

❯ yarn e2e-test-ios
yarn run v1.22.22
$ ./scripts/maestro-test-ios.sh

Waiting for flows to complete...
[Passed] flatlist (7s)
[Passed] text (15s)
[Passed] modal (10s)
[Passed] image (4s)
[Passed] button (6s)
[Passed] legacy-native-module (16s)
[Passed] pressable (16s)
[Passed] new-arch-examples (17s)

8/8 Flows Passed in 1m 31s

✨  Done in 97.53s.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Contributor A React Native contributor. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jun 12, 2025
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

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

@janicduplessis Thank you so much for fixing this!

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jun 16, 2025
@facebook-github-bot
Copy link
Contributor

@cipolleschi merged this pull request in 7e2f17f.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @janicduplessis in 7e2f17f

When will my fix make it into a release? | How to file a pick request?

@janicduplessis janicduplessis deleted the @janic/accessibility-label branch June 16, 2025 17:40
cipolleschi added a commit that referenced this pull request Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Contributor A React Native contributor. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants