Skip to content

Reuse querySelectorAll for getElementsByTagName - #720

Open
andrewiggins wants to merge 3 commits into
optimize-selectorsfrom
refactor-getElementsByTagName
Open

andrewiggins wants to merge 3 commits into
optimize-selectorsfrom
refactor-getElementsByTagName

Conversation

@andrewiggins

@andrewiggins andrewiggins commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Builds on #719. This layer contains only the tag-name lookup refactor and its required selector support.

  • Replace the dedicated getElementsByTagName() descendant loop with a structured matcher passed to querySelectorAll().
  • Introduce an internal qualified-name matcher: DOM tag-name lookup compares the full qualified name, while CSS type selectors continue comparing localName.
  • Supply precomputed qualified names through htmlName rather than value, extending the normalized-name matcher contract and type tests.
  • Preserve wildcard lookup, string conversion, ASCII-only HTML query normalization, and case-sensitive foreign-name matching.
  • Return the existing static NodeList, including item() access; this does not implement a live HTMLCollection.

This shares traversal and matching code; it is not an overall performance-speedup claim. Earlier synthetic Node/V8 measurements of this approach remained slower than the dedicated loop. Those measurements were not a final-commit or browser benchmark. Plain-array results and scalar matcher experiments are not included.

Validation

  • Full polyfill unit suite: 434 tests passed across 30 files.
  • Polyfill TypeScript check passed.
  • Prettier and diff checks passed.
  • Added structured-matcher coverage verifying that HTML matching uses htmlName, foreign matching uses the original name, and neither uses value.

Stack created with GitHub Stacks CLIGive Feedback 💬

@andrewiggins
andrewiggins added this pull request to stack #721 September 17, 2026 16:46
@github-actions

This comment has been minimized.

@andrewiggins
andrewiggins force-pushed the refactor-getElementsByTagName branch from b976a93 to 28673c4 Compare September 17, 2026 18:06
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