Repository navigation
perf: skip provably ambiguous XPath selector searches - #62
Merged
Merged
Conversation
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.
Mirrored, attribute-heavy branches currently exhaust all 256 XPath candidates even though none can distinguish the target. A bounded preflight on the normalized XPath tree now proves ambiguity when another node shares the target's tag, full attribute map and sibling position, and contains its ancestor shapes as an ordered subsequence. When that proof succeeds, generation immediately returns the already validated absolute fallback; otherwise the existing Robula-style search, ranking and budgets run unchanged.
The preflight applies only to searches larger than the 128-entry compilation cache and caps shape comparisons at the candidate count. There are no dependency or API changes.
Coverage
attrs-128anddeep-attrs, including repeated generation and target identity.Measurements
Full selector benchmark: all seven scenarios, both CSS and XPath, 15 warm repeats per scenario, release build, CPython 3.12.14, AMD EPYC 9V74. These local before/after measurements use baseline
2633b5a; the patch was subsequently rebased onto current v0.14.0master(8927546). The fixture data-attribute candidate grammar is unchanged by the intervening href/src ranking update.Profiling attributes most latency to the 227 ancestor candidates: attrs-128 spends approximately 131 ms executing them and 25 ms compiling them; deep-attrs spends approximately 278 ms executing them and 26 ms compiling them. The shortcut removes these evaluations for provably indistinguishable branches. Distinguishable documents retain the original search plus bounded preflight overhead; these are not general speedup guarantees for arbitrary HTML.
Validation on current master
-D warnings -A clippy::collapsible_if: passed. Unmodified strict Clippy reports two pre-existingcollapsible_iflints in the href/src ranking code added by Prefer scraping-stable href/src attributes in XPath generation #61, outside this patch.The preflight proof must be updated if the candidate grammar later adds text predicates, ancestor positions, or other distinguishing transformations.