-
Notifications
You must be signed in to change notification settings - Fork 470
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
feat: Prioritize accessible names check higher than inaccessibility check in byRole
queries
#1068
feat: Prioritize accessible names check higher than inaccessibility check in byRole
queries
#1068
Conversation
aeb7f4a
to
a361d1b
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Codecov Report
@@ Coverage Diff @@
## main #1068 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 25 25
Lines 952 952
Branches 311 311
=========================================
Hits 952 952
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit f7ffeac:
|
Thanks for this work. Taking this change for a spin in mui/material-ui#29368
Could you elaborate a bit more on this? Did you assume this from usage in some repository? Did you notice this during profiling? In which cases is it more expensive? It's not at all clear to me that visibility checks are more expensive since the accessible name can potentially compute styles for more elements. So this really needs a data-driven approach to determine the best heuristic. |
Fair point, I don't have the data though, I kinda hope to have some folks testing this out and gather some real life performance data in some of the popular repos 😅 (
However, the established workaround of the original issue could more or less back this up though. We're already suggesting users to try disabling the visibility check altogether to speed up the performance, that could only mean that the check itself is less important and costly, no? I understand that with the manual opt-out, the users got to choose whether to disable it or not though. In addition, I'd assume that most of the getByRole('button', { name: 'Click me' }); The two major inputs from the user here are, obviously, To quote your study here:
If I understand this correctly, it means that the But again, it's all just my guess. I'd love to have some real world data to support the theory 🙇♂️ . |
Thanks for the explanation. This makes more sense to me now. Did some analysis in mui/material-ui#29368. Looks safe to land. |
byRole
queriesbyRole
queries
Any plans to merge this? Or should we get more approvals from maintainers? |
Just wanted to let this sit so that everybody has a chance to review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM.
Although I agree with @markerikson that it could be made faster (even if it's just a little bit) if all filter
statements are merged into 1 statement.
🎉 This PR is included in version 8.11.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Just as an FYI, I tried specifically adding a dep on Before:
After:
No other code changes. So, this distinctly made some improvement. (I still don't think the test file should be taking anywhere this long to begin with, but I haven't had time to really drill down and see what else is taking it so long.) |
…heck in `byRole` queries (testing-library#1068) Co-authored-by: eps1lon <silbermann.sebastian@gmail.com>
What:
Related to #698 and #820.
*ByRole
queries are filtering inaccessibility (hidden: false
) earlier than accessible names. This PR changes that by prioritizing accessible names over inaccessibility. Hopefully to achieve better performance in most cases.Why:
As stated in #820 (comment), one of the escape hatches to improve the performance of the
*ByRole
queries is to passhidden: true
to the options. The reason is that the visibility check is more expensive in most cases. People are already using this technique to improve their queries' performance by setting the default options to true globally. The downside of this technique is obviously that we'd lose the visibility check for better and predictable queries.What if instead of removing the inaccessibility check altogether, we just have to move the order lower? Since the query is really just a set of filter functions, if we can run the faster filter first and short-circuiting most of the candidates, then hopefully we don't have to run the slower inaccessibility check on so many elements.
For a naive test with 1000 buttons all with different names in jsdom environment, selecting the last element takes around 2 seconds. After applying this changes, it only takes around 1 second in average on my machine. It's not a lot but seems like a free win to me.
Obviously it doesn't reflect the real world usage, but I'd expect the usage of accessible names check are more frequent than the inaccessibility check. It'd only be slower if there are multiple elements with the same name but only a part of them are accessible/visible. I can't think of a case where this would be a common scenario in testing. Additionally, people are already opting-out of the inaccessibility check globally, this should have little impact for them.
Preferably, it'd be nice to have it tested in some real world repos to see if it actually improves the performance though.
How:
Move the inaccessibility check lower to the last.
Checklist:
docs site (I don't think this needs to be added to the documentation site. A record in changelog should be fine?)