Repository navigation
fix(xpath): quadratic attribute name tests, and XPath over any tree - #197
Open
jamesconwaydev wants to merge 3 commits into
Open
jamesconwaydev wants to merge 3 commits into
jamesconwaydev wants to merge 3 commits into
Conversation
This branch has not been 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.
Syncs Netweir 0196e9e: netweir/netweir#366 and netweir/netweir#369. Part of #171.
Problem.
Doc::attr_at, which calledtree.attrs(owner).nth(index)and walked every attribute before the one it wanted. A name test does that once per attribute, so/a/@sameon one element with 20,001 attributes took 0.24 s at 5,000, 0.97 s at 10,000 and 3.89 s at 20,000. A page built to stall a crawler's XPath could use it.parsec-xpathcould only queryparsec-html-core'sDocument, soparsec-xml(feat(xml): Parsec had no XML parser, and XML can't go through HTML's #198) had no XPath.Change.
Document::attr_atandDocument::attr_countread attributes in constant time./a/@sameat 20,000 now takes 4.2 ms.parsec-xpathreads trees through aTreetrait (src/tree.rs). The impl forparsec::Document, andXmlTreefor an XML document built into the HTML tree, sit behind a defaulthtmlfeature (src/html.rs). Withdefault-features = false, the crate depends onstackeralone.htmlfeature,parsec-html-coremade optional, andrequired-featureson thexpathandlibxml2tests.parsec-xpath --no-default-features.Doc::xmlandNamespaces::id_ofare gone andItem::Attrlost itsnsfield. Parsec's own uses (the C API, Python and WebAssembly) already matchedItem::Attr { owner, index, .. }and compile unchanged. In XML,local-name()of a processing instruction is now its whole target, as libxml2 has it. CHANGELOG has both.Tests.
tests/tree.rsqueries a tree written by hand, covering names, namespaces, attributes (xmlnsleft out), text, processing instructions,id()andlang(), so the trait is proven apart from the HTML tree. Netweir'smany_declarations_and_prefixed_attributes_stay_linearfails without theattr_atfix. Here: the drift check against 0196e9e passes;cargo testfor parsec-xpath (with and without default features), parsec-html-core, parsec-html and parsec-capi passes; workspace clippy, fmt and the header check are clean.