Skip to content

Optimize selector matching and clarify matcher contracts - #719

Open
andrewiggins wants to merge 8 commits into
mainfrom
optimize-selectors
Open

andrewiggins wants to merge 8 commits into
mainfrom
optimize-selectors

Conversation

@andrewiggins

@andrewiggins andrewiggins commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Avoid allocating the remaining selector-parts array when matching the terminal part, while preserving ancestor/sibling search behavior.
  • Precompute ASCII-lowercased HTML comparison names for CSS element and attribute selectors instead of normalizing for every candidate.
  • Read the fixed id and class attributes directly without redundant name normalization, and inline the remaining attribute lookup.
  • Define discriminated matcher contracts with type coverage, keeping one parser construction site and a minimal parser diff.

A shared htmlName property holds precomputed HTML names and is required for element and attribute matchers. name preserves the original spelling for foreign-element matching, while value retains the selector payload. Parser construction uses the property order type, name, htmlName, value. Matcher arrays and NodeList query results are unchanged.

This is the lower layer of the stack. It leaves getElementsByTagName() and its tests unchanged; #720 adds qualified-name matching and reuses the optimized engine for that lookup.

Validation

  • Full polyfill unit suite: 428 tests passed across 30 files.
  • Polyfill TypeScript check passed.
  • Prettier and diff checks passed.

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 changed the title optimize selectors Optimize selector matching and clarify matcher contracts Sep 17, 2026

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