Repository navigation
perf(web): pre-parse selectors once at bucket build; -39% sel_match - #905
Merged
Merged
Conversation
`simple_match` / `simple_match_ctx` re-derived, from selector TEXT, on EVERY candidate x node pair (~4,078 per 8-page bench run), information that does not depend on the node at all: the base/pseudo split, the `::` probe, the `[...]` bracket-group walk plus `attr_selector_matches`' `^=`/`$=`/`=` probing, flag strip and unquote, `class_has_all`'s per-node `.a.b.c` split, the pseudo-class chain walk (TWICE -- once in `simple_match`, again in `_pseudo_ctx_matches`), the `:not/:is/:where/:has` comma splits, and `_nth_child_matches`' `an+b` parse. In the interpreter that is per-character `sel[i:i+1]` slicing, which round 8 named as the likely dominant cost without sizing it. Each selector part is now parsed ONCE into a `ParsedSel` record where `build_rule_buckets` runs, stored on `RuleBuckets.parsed_groups` (one construction site, unlike `Rules`), indexed exactly like `rules.group_parts`. The per-node path -- `simple_match_parsed`, `_pseudo_ctx_matches_parsed`, `simple_match_ctx_parsed`, `selector_group_matches_node_parsed` -- consumes only the record and never touches selector text. One pre-parsed pseudo chain feeds both halves, so round 8's duplicate chain walk disappears with it. The `_wsc_armed()` wrapper shape is preserved so `sel_match_ms` measures the same span either side. Semantics are byte-identical by construction: the parser mirrors `simple_match`'s check order and reuses the same helpers, and `dead` is set only where the text path returns false regardless of the node. `check_tag` / `check_id` are explicit flags, not `""` sentinels, because `#` -> `id == ""` really does mean "must have no id". New equivalence oracle `simple_web_layout_debug_selector_parse_equivalence(html, max_nodes)` runs BOTH paths over every distinct selector part x every node (base AND full-context match) and every real candidate rule-group, pinned by test/01_unit/browser_engine/web_selector_parsed_equivalence_spec.spl (twin at test/unit/): 10/10 pass, 177,949 comparisons over the 8 catalog pages plus an adversarial fixture, 0 mismatches. The adversarial half earned its keep on the first run: `MISMATCH base node=27 sel=input:disabled text=false parsed=true`. `:disabled` never matches in the text path on EITHER branch -- without the attribute the `_is_interaction_state_pseudo` arm answers true and returns false; with it that arm answers false and the chain falls through to the catch-all arm, which also returns false. The first cut implemented the apparent intent and was reverted: `:disabled` now joins the dead set, reproducing the renderer exactly. The quirk is pre-existing at origin/main and documented in `_pseudo_code_for`; changing it is a separate decision, not a side effect of a perf round. The catalog pages would never have caught this -- they contain 25 distinct selectors and no `:disabled`. Evidence (doc/10_metrics/ui/web_perf_round9_2026-09-13.md): - 12 alternating A/B pairs. Quiet-host sweep: sel_match 1009-1016 ms -> 613-638 ms (-39%) with cas_tail and sel_sort flat. Across all 12 pairs, normalised by cas_tail as the load proxy, before 1.83-1.99 vs after 1.09-1.16 -- non-overlapping, non-adjacent. - candidates=4024 and selector_calls=4078 on all 24 runs: the candidate set is provably unchanged, so the delta is match cost, not pruning. - Draw IR sha256 byte-identical on all 8 pages across all 24 runs, equal to the set round 8 recorded. - GPU boundary audit: PASS, 2 frames, host_pixel_iterations=0. - 26 selector/style/cascade/inherit specs + web_cold_pipeline_memo_spec: verdict lines byte-identical before vs after (19 OK, 7 pre-existing ERROR). - Per-page cold pipeline totals are reported but WITHDRAWN as evidence: the ~400 ms saving is below this host's run-to-run swing on a 3-6 s page and the sign flips between pairs. Target B (cas_tail, ~535 ms) deliberately untouched -- it was the control that made this measurement trustworthy. Residuals named in the record: `:not/:is/ :where/:has` options are pre-split but not recursively pre-parsed, and the `:root[attr]` expression stays text. Pre-push guards, rc read into a variable on the line after each invocation (never through a pipe): - check-no-conflict-markers-push rc=0 PASS, 5 files scanned, 0 markers - check-tree-size-push rc=0 PASS, selftest 24/24, 0 structural faults - check-no-revert-push rc=0 PASS, selftest 3/3, 5 files, 0 reverts - check-hook-installation rc=0 PASS, 12 checks, wiring intact - check-test-tree-divergence-delta rc=0 PASS — 3213 pre-existing offender(s), 0 introduced by this range Divergence-delta step-over record (required by .claude/rules/vcs.md when landing on a delta-PASS). The pre-existing red is IDENTICAL at base and tip. Base verdict at origin/main: `FAIL — 3941 diverged vs 965 baselined (3079 new, 103 fixed-but-still-baselined); 32 mirror-only (31 unallowlisted, 0 stale-allowlist)`. Offender list (3,941 lines) saved by the helper to `$TMPDIR/test_tree_divergence_preexisting.txt`. The only mirror-pair paths this range touches are the two copies of the new spec, added byte-identical: test/01_unit/browser_engine/web_selector_parsed_equivalence_spec.spl test/unit/browser_engine/web_selector_parsed_equivalence_spec.spl Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TVraTPgGDVypESTsVqXPgi
ormastes
had a problem deploying
to
self-review-admission
September 13, 2026 12:37 — with
GitHub Actions
Error
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Web-rendering perf round 9, Target A: the structural fix rounds 5-8 identified but did not implement. Three prior rounds on
sel_matchended in honest negatives; this one lands with 12 A/B pairs.What was re-parsed per node
simple_match/simple_match_ctxran ~4,078 times per 8-page bench run, and every call re-derived from selector TEXT things that do not depend on the node: the base/pseudo split, the::probe, the[...]bracket walk plusattr_selector_matches'^=/$=/=probing, flag strip and unquote,class_has_all's per-node.a.b.csplit, the pseudo-class chain walk twice (once insimple_match, again in_pseudo_ctx_matches), the:not/:is/:where/:hascomma splits, and_nth_child_matches'an+bparse. In the interpreter that is per-charactersel[i:i+1]slicing — which round 8 named as the likely dominant cost without sizing it.The change
Each selector part is parsed once into a
ParsedSelrecord wherebuild_rule_bucketsruns, stored onRuleBuckets.parsed_groups(one construction site, unlikeRules), indexed exactly likerules.group_parts. The per-node path —simple_match_parsed,_pseudo_ctx_matches_parsed,simple_match_ctx_parsed,selector_group_matches_node_parsed— consumes only the record and never touches selector text. One pre-parsed chain feeds both pseudo passes, so round 8's duplicate chain walk disappears with it. The_wsc_armed()wrapper shape is preserved sosel_match_msmeasures the same span either side.Equivalence — and the three divergences it caught
New oracle
simple_web_layout_debug_selector_parse_equivalence(html, max_nodes)runs both paths over every distinct selector part × every node (base and full-context match) and every real candidate rule-group, pinned bytest/01_unit/browser_engine/web_selector_parsed_equivalence_spec.spl(byte-identical twin attest/unit/): 10/10 pass, 177,949 catalog comparisons over 3,419 nodes + an adversarial fixture, 0 mismatches.Two tiers, because the eight catalog stylesheets contain only 25 distinct selectors between them — catalog-only coverage proves almost nothing about selector semantics. The adversarial half found three real divergences, each added as a fixture row, confirmed failing, then fixed:
:disablednever matches in the text path, on either branch. Without the attribute the_is_interaction_state_pseudoarm answers true and returns false; with it, that arm answers false and the chain falls through to the catch-all arm, which also returns false. The first cut implemented the apparent intent and made it match — a behaviour change, reverted. The quirk is pre-existing atorigin/main, documented in_pseudo_code_for, and changing it is a separate decision.:has()split is a pass-through, not a rejection.simple_match's elif-chain excludeshas, sosimple_match("ul:has()", <ul>)returns true and only_pseudo_ctx_matchesrejects. Invisible on a rightmost part, decisive on an ancestor part (ul:has() > li,ul:has(a,,b) span, a 17-option:has), which runssimple_matchonly.:rootis parsed then ignored.:root(x)takes the(branch and therootarm checks onlytag != "html"; only:root[...]carries an attribute test. The field is nowpseudo_root_attrs, written solely by the[branch.None of these three shapes occurs in the catalog, so the Draw IR digests never moved for any of them — which is exactly why the adversarial fixture exists.
Measurements
12 alternating A/B pairs, file swapped in place between runs,
SIMPLE_WEB_STYLE_COUNTERS=1.sel_match1009-1016 ms → 613-638 ms (−39%) with controlscas_tail(532-540 → 533-569) andsel_sort(92-94 → 93-96) flat.cas_tailas the load proxy: before 1.83-1.99, after 1.09-1.16 — non-overlapping and non-adjacent.candidates=4024andselector_calls=4078on all 24 runs: the candidate set is provably unchanged, so the delta is match cost, not pruning.sec_select_ms1360-1369 → 966-1007: the saving flows through, not sideways.web_selector_parsed_equivalence_specPASS — 2 frame(s) audited, host_pixel_iterations=0, readbacks_per_frame<=1, submits_per_frame<=1web_cold_pipeline_memo_specWithdrawn: per-page cold pipeline totals. The ~400 ms saving is below this host's run-to-run swing on a 3-6 s page and the sign flips between pairs on the same page; they are recorded in the metrics doc and explicitly not used as evidence. The load-robust claim is the control-normalised
sel_matchratio.Pre-push guards (rc read into a variable on the next line, never through a pipe): conflict-markers
rc=0, tree-sizerc=0(selftest 24/24), no-revertrc=0(selftest 3/3), hook-wiringrc=0(12 checks), divergence-deltarc=0—PASS — 3213 pre-existing offender(s), 0 introduced by this range. The pre-existing red is identical at base and tip; the offender list and base verdict are recorded in the commit message as.claude/rules/vcs.mdrequires.Target B (
cas_tail, ~535 ms) deliberately untouched — it was the control that made this measurement trustworthy. Next round's target, localised in the doc: css-layout (184 ms) and css-paint (238 ms) carry 79% of it.Record:
doc/10_metrics/ui/web_perf_round9_2026-09-13.md🤖 Generated with Claude Code
https://claude.ai/code/session_01TVraTPgGDVypESTsVqXPgi