Skip to content

bench: nothing timed selector matching against Lexbor - #73

Merged
jamesconwaydev merged 4 commits into
mainfrom
bench-selectors
Nov 16, 2026
Merged

jamesconwaydev merged 4 commits into
mainfrom
bench-selectors

Conversation

@jamesconwaydev

Copy link
Copy Markdown
Collaborator

Problem

bench/ timed parsing only. Nothing compared Parsec's selector matching with Lexbor's, so the README couldn't say how queries compare, and nobody would have seen that :nth-child(an+b) was quadratic in the number of siblings.

Change

  • bench/src/selectors.rs runs the 32-selector battery from examples/select.rs over the 13 real pages: Parsec's SelectorList::select against Lexbor's lxb_selectors_find, with both documents built beforehand. Each time is the median of 30 runs after a warm-up. Lexbor is set up as its examples/lexbor/selectors/normal_way.c does, with LXB_SELECTORS_OPT_MATCH_FIRST so a node is reported once, as querySelectorAll does.
  • The table shows the match counts, and both counts when the two differ, so a time is never compared across different answers.
  • bench … selectors runs only that table; a plain run prints it after the parse tables.
  • Syncs netweir-html at 6034a8e (perf(css): :nth-child(an+b) recounted every earlier sibling per element netweir/netweir#324), which caches each element's position among its siblings. Before it, p:nth-child(2n+1) took Parsec 314 ms over the pages, nearly as slow as Lexbor.
  • Fixes the bench header's commit stamp, which stayed at whichever commit the bench was first built at: build.rs watched .git/HEAD, which a commit doesn't touch.
  • README: a selector paragraph with these numbers. ROADMAP: M1 done.

Results (Apple M2 Max, three runs, within 2% of each other)

  • All 32 selectors: Parsec 226 ms, Lexbor 728 ms, 3.22×. Parsec is ahead on every selector, by 1.11× (body *:last-child) to 3.9× (tr:nth-of-type(odd)), and 30.8× on p:nth-child(2n+1), which takes Lexbor 339 ms.
  • Before the sync, the total was 1.32×.
  • One count differs: [href], 82,212 against Lexbor's 82,220. Lexbor also matches SVG's xlink:href; a selector with no namespace prefix matches attributes with no namespace, so Parsec's count is the right one.

Tests

  • cargo fmt, cargo clippy --release -- -D warnings and cargo deny check licenses bans sources on bench/ are clean.
  • cargo test --test css passes, including the new stepped_child_index_counts_mixed_siblings from Netweir.
  • scripts/check-headers.sh passes.

Fixes #3

A table after the pages runs the 32 selectors from
examples/select.rs over the 13 real pages, Parsec's select against
Lexbor's lxb_selectors_find with LXB_SELECTORS_OPT_MATCH_FIRST, both
on documents built beforehand. Each row is the median of 30 runs and
shows both match counts when they differ. `selectors` on the command
line runs only this table.
Brings in the cached sibling positions for :nth-child(an+b) and its
kin, which had counted every earlier sibling for each element.
build.rs reran when .git/HEAD changed, but a commit moves the branch
HEAD points to and leaves HEAD alone, so the stamp went stale.
Adds the selector results from bench/ and marks M1 done in the
roadmap.
@jamesconwaydev jamesconwaydev added this to the M1. Proof milestone Nov 16, 2026
@jamesconwaydev jamesconwaydev self-assigned this Nov 16, 2026
@jamesconwaydev jamesconwaydev added the bench Benchmarks against Lexbor and others label Nov 16, 2026
@jamesconwaydev
jamesconwaydev enabled auto-merge (squash) November 16, 2026 03:00
@jamesconwaydev
jamesconwaydev merged commit cda1adc into main Nov 16, 2026
12 checks passed
@jamesconwaydev
jamesconwaydev deleted the bench-selectors branch November 16, 2026 03:02
@github-project-automation github-project-automation Bot moved this from Todo to Done in Parsec roadmap Nov 16, 2026
@jamesconwaydev jamesconwaydev mentioned this pull request Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bench Benchmarks against Lexbor and others

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Benchmark selector matching against Lexbor

1 participant