Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Does using within actually have any perf benefits? #1320

Answered by MatanBobi
hrmJ asked this question in Q&A
Discussion options

Hi,

I have some tests that initially render a rather large DOM. I have been under the assumption that using queries like screen.getBy... would potentially be slower than queries narrowed down using within . Should this be the case? I don't seem to notice a difference and actually the within-queries often seem slower. Using within does give a lot nicer error output when the element searched for is not found, but is that the only benefit?

You must be logged in to vote

The only thing that happens in within is we're binding the queries to the element, so instead of using screen which will run document.body.querySelectorAll, we'll run element.querySelectorAll. I think it will have a performance impact only if the document.body is really, really big. I believe that within's purpose is not a performance boost rather than narrowing down the query to a specific area of a page.

Replies: 1 comment

Comment options

The only thing that happens in within is we're binding the queries to the element, so instead of using screen which will run document.body.querySelectorAll, we'll run element.querySelectorAll. I think it will have a performance impact only if the document.body is really, really big. I believe that within's purpose is not a performance boost rather than narrowing down the query to a specific area of a page.

You must be logged in to vote
0 replies
Answer selected by MatanBobi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /