Skip to content

perf(queries): Reduce text query overhead - #1390

Open
scttcper wants to merge 2 commits into
testing-library:mainfrom
scttcper:scttcper/text-query-fast-paths
Open

scttcper wants to merge 2 commits into
testing-library:mainfrom
scttcper:scttcper/text-query-fast-paths

Conversation

@scttcper

@scttcper scttcper commented Sep 17, 2026 •

Copy link
Copy Markdown

Skip selector matching when an element's tag rules out a match, and collect direct text nodes in one pass. Keep the existing selector checks for candidate tags and custom ignore options.

Combined changes vs upstream on a 1,002-element fixture, median of nine paired batches:

Environment Before After Reduction
jsdom 20.0.0 2.203 ms 1.403 ms 36.3%
jsdom 30.1.0 2.652 ms 1.143 ms 56.9%
Happy DOM 20.14.5 0.482 ms 0.256 ms 46.9%
Chrome 153 0.514 ms 0.330 ms 35.9%
Firefox 142 0.533 ms 0.290 ms 45.6%
WebKit 26 0.357 ms 0.197 ms 44.9%

matches() calls drop from 2,005 to 201 per query. These are synthetic query timings, not whole-suite gains. The input-only and script/style-only cases still regress in some environments, up to 10.7%.

Full evidence and runner: 78 benchmark cases, 73,012 behavior comparisons with no differences. Node stayed at 24.14, below jsdom 30.1's declared 24.15 minimum.

Check the tag before matching the fixed input and default ignore selectors.
Keep the existing selector checks for candidate tags and custom options.

Co-Authored-By: Codex <noreply@openai.com>
@codesandbox-ci

codesandbox-ci Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

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 d8fdfc3:

Sandbox Source
react-testing-library-examples Configuration

Avoid intermediate arrays when collecting direct text nodes. Iterate childNodes and append Text.data while preserving whitespace and excluding descendants.

Co-Authored-By: Codex <noreply@openai.com>
@scttcper scttcper changed the title perf(queries): Skip selector matches for unrelated tags perf(queries): Reduce text query overhead Sep 17, 2026
@scttcper
scttcper marked this pull request as ready for review September 17, 2026 06:23

This branch has not been deployed

No deployments
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.

1 participant